|
DAWorkbench 0.0.1
DAWorkbench API
|
QJsonObject 和 pybind11::dict 之间的转换函数 更多...
#include "DAPyBindQtGlobal.h"#include <QJsonObject>#include <QJsonArray>#include <QJsonValue>#include <QJsonDocument>#include <QVariant>#include "DAPybind11InQt.h"命名空间 | |
| namespace | DA |
| 序列化类都是带异常的,使用中需要处理异常 | |
函数 | |
| pybind11::dict | DA::PY::qjsonObjectToPyDict (const QJsonObject &jsonObj) |
| pybind11::list | DA::PY::qjsonArrayToPyList (const QJsonArray &jsonArray) |
| 将 QJsonArray 转换为 pybind11::list | |
| pybind11::object | DA::PY::qjsonValueToPyObject (const QJsonValue &jsonValue) |
| 将 QJsonValue 转换为 pybind11::object | |
| QJsonObject | DA::PY::pyDictToQJsonObject (const pybind11::dict &pyDict) |
| QJsonArray | DA::PY::pyListToQJsonArray (const pybind11::list &pyList) |
| 将 pybind11::list 转换为 QJsonArray | |
| QJsonValue | DA::PY::pyObjectToQJsonValue (const pybind11::object &pyObj) |
| 将 pybind11::object 转换为 QJsonValue | |
| pybind11::dict | DA::PY::jsonStringToPyDict (const QString &jsonStr) |
| 将 JSON 字符串转换为 pybind11::dict | |
| QString | DA::PY::pyDictToJsonString (const pybind11::dict &pyDict, int indent=0) |
| 将 pybind11::dict 转换为 JSON 字符串 | |
QJsonObject 和 pybind11::dict 之间的转换函数
这个模块提供了 Qt 的 JSON 类型和 Python 字典之间的双向转换功能。 它依赖于 DAPybind11QtTypeCast 中的现有转换函数,并专门处理 JSON 结构。
| DAPYBINDQT_API pybind11::dict DA::PY::jsonStringToPyDict | ( | const QString & | jsonStr | ) |
将 JSON 字符串转换为 pybind11::dict
将 JSON 格式的字符串解析为 QJsonObject,然后转换为 Python 字典。
| jsonStr | JSON 格式的字符串 |
| 如果 | JSON 解析失败,返回空字典 |
| DAPYBINDQT_API QString DA::PY::pyDictToJsonString | ( | const pybind11::dict & | pyDict, |
| int | indent = 0 |
||
| ) |
将 pybind11::dict 转换为 JSON 字符串
将 Python 字典转换为 QJsonObject,然后序列化为 JSON 字符串。
| pyDict | 要转换的 pybind11::dict |
| indent | 缩进空格数,0 表示紧凑格式 |
| DAPYBINDQT_API QJsonArray DA::PY::pyListToQJsonArray | ( | const pybind11::list & | pyList | ) |
将 pybind11::list 转换为 QJsonArray
递归地将 Python 列表转换为 QJsonArray,支持嵌套的 Python 结构。
| pyList | 要转换的 pybind11::list |
| DAPYBINDQT_API QJsonValue DA::PY::pyObjectToQJsonValue | ( | const pybind11::object & | pyObj | ) |
将 pybind11::object 转换为 QJsonValue
将单个 Python 对象转换为对应的 QJsonValue。
| pyObj | 要转换的 pybind11::object |
| DAPYBINDQT_API pybind11::list DA::PY::qjsonArrayToPyList | ( | const QJsonArray & | jsonArray | ) |
将 QJsonArray 转换为 pybind11::list
递归地将 QJsonArray 转换为 Python 列表,支持嵌套的 JSON 结构。
| jsonArray | 要转换的 QJsonArray |
| DAPYBINDQT_API pybind11::object DA::PY::qjsonValueToPyObject | ( | const QJsonValue & | jsonValue | ) |
将 QJsonValue 转换为 pybind11::object
将单个 QJsonValue 转换为对应的 Python 对象。
| jsonValue | 要转换的 QJsonValue |