DAWorkbench 0.0.1
DAWorkbench API
载入中...
搜索中...
未找到
DAPyJsonCast.h 文件参考

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 结构。

注解
此文件函数会抛出异常

函数说明

◆ jsonStringToPyDict()

DAPYBINDQT_API pybind11::dict DA::PY::jsonStringToPyDict ( const QString &  jsonStr)

将 JSON 字符串转换为 pybind11::dict

将 JSON 格式的字符串解析为 QJsonObject,然后转换为 Python 字典。

参数
jsonStrJSON 格式的字符串
返回
转换后的 pybind11::dict
异常
如果JSON 解析失败,返回空字典

◆ pyDictToJsonString()

DAPYBINDQT_API QString DA::PY::pyDictToJsonString ( const pybind11::dict &  pyDict,
int  indent = 0 
)

将 pybind11::dict 转换为 JSON 字符串

将 Python 字典转换为 QJsonObject,然后序列化为 JSON 字符串。

参数
pyDict要转换的 pybind11::dict
indent缩进空格数,0 表示紧凑格式
返回
JSON 格式的字符串

◆ pyListToQJsonArray()

DAPYBINDQT_API QJsonArray DA::PY::pyListToQJsonArray ( const pybind11::list &  pyList)

将 pybind11::list 转换为 QJsonArray

递归地将 Python 列表转换为 QJsonArray,支持嵌套的 Python 结构。

参数
pyList要转换的 pybind11::list
返回
转换后的 QJsonArray

◆ pyObjectToQJsonValue()

DAPYBINDQT_API QJsonValue DA::PY::pyObjectToQJsonValue ( const pybind11::object &  pyObj)

将 pybind11::object 转换为 QJsonValue

将单个 Python 对象转换为对应的 QJsonValue。

参数
pyObj要转换的 pybind11::object
返回
转换后的 QJsonValue

◆ qjsonArrayToPyList()

DAPYBINDQT_API pybind11::list DA::PY::qjsonArrayToPyList ( const QJsonArray &  jsonArray)

将 QJsonArray 转换为 pybind11::list

递归地将 QJsonArray 转换为 Python 列表,支持嵌套的 JSON 结构。

参数
jsonArray要转换的 QJsonArray
返回
转换后的 pybind11::list 对象

◆ qjsonValueToPyObject()

DAPYBINDQT_API pybind11::object DA::PY::qjsonValueToPyObject ( const QJsonValue &  jsonValue)

将 QJsonValue 转换为 pybind11::object

将单个 QJsonValue 转换为对应的 Python 对象。

参数
jsonValue要转换的 QJsonValue
返回
转换后的 pybind11::object