我有兴趣了解我们如何使用 Qt 的QJsonDocument来解析来自简单嵌套 JSON的所有条目(因为我刚刚开始研究这个)。
嵌套 json 示例:
{
"city": "London",
"time": "16:42",
"unit_data":
[
{
"unit_data_id": "ABC123",
"unit_data_number": "21"
},
{
"unit_data_id": "DEF456",
"unit_data_number": "12"
}
]
}
我可以像这样解析它的非嵌套部分:
QJsonObject jObj;
QString city = jObj["city"].toString();
QString time = jObj["time"].toString();