qjson

Qt 常用JSON解析示例

淺唱寂寞╮ 提交于 2020-08-10 19:54:13
JSON的解析要对照JSON字符串来理解,关于JSON字符串的介绍,可以参考 JSON简介 首先,解析和构建都要包含如下头文件: #include <QJsonDocument> #include <QJsonObject> #include <QJsonArray> 示例1:和风天气实时数据 这个 JSON 字符串中 HeWeather6 键的值是一个数组,数组内只有 1 个 JSON 对象,这个对象里又嵌套了几个 JSON 对象。 { "HeWeather6": [{ "basic": { "cid": "CN101010700", "parent_city": "北京", "cnty": "中国", }, "status": "ok", }] } 主要是 JSON 的多层嵌套的解析。解析函数: int Parse_HeWeather_Now_Json(void) { QJsonParseError err_rpt; QJsonDocument root_Doc = QJsonDocument::fromJson(he_now_json, &err_rpt); // 字符串格式化为JSON if(err_rpt.error != QJsonParseError::NoError) { qDebug() << "JSON格式错误"; return -1; } else //

Construct QString from QJsonArray in Qt

偶尔善良 提交于 2020-01-16 19:45:09
问题 While trying to construct a QString from values from a QJsonArray , I get the following error: error: passing 'const QString' as 'this' argument discards qualifiers [-fpermissive] . Dunno where I am getting it wrong in this code: QString <CLASS_NAME>::getData(QString callerValue) { QString BASE_URL = "<URL>"; QString stringToReturn = ""; QObject::connect(manager, &QNetworkAccessManager::finished, this, [=](QNetworkReply *reply) { QByteArray barr = reply->readAll(); QJsonParseError jpe;

How to serialize to JSON in Qt

江枫思渺然 提交于 2019-12-20 19:43:13
问题 How can I JSON serialize a QVariant (or other type of data) in Qt. I don't want to use an external third party library like QJson 回答1: Just to mention, as of Qt5, JSON is officially supported: JSON Support in Qt QVariant id(1), name("John Doe"); QJsonObject json; json["Name"] = name.toString(); json.insert("id", id.toInt()); 回答2: Parsing JSON with QT using standard QT library. BTW: why don't you want to use QJson? It nicely encapsulates all the QScriptValueIterator stuff, making your code

How to change QJsonObject value in a QJson hierarchy without using copies?

拜拜、爱过 提交于 2019-12-10 00:52:31
问题 I am currently using Qt5.0 with the core QJson library to handle some data for the program I am developing. To set the scene for this question I will provide you with some JSON data that illustrates my problem: { "CLOCKS": [ { "ID": "clk", "MAX": 2e+08, "MIN": 1e+07, "VALUE": "no_clock" }, { "ID": "memclk", "MAX": 2e+08, "MIN": 1e+07, "VALUE": "memclk" } ] } Here we have a parent QJsonObject containing a single key 'CLOCKS'. The value for this key is a QJsonArray of QJsonObjects that contain

QJSON using in Mac - getting some issues

落爺英雄遲暮 提交于 2019-12-08 01:16:13
问题 I am using the QJson for parsing. But I am stuck up with some issues. I have used the following code: void CityBook ::getCityList(QUrl url) { //!connect(cityReply, SIGNAL(readyRead()),this, SLOT(httpReadyRead())); cityGuideNetworkAccessManager = new QNetworkAccessManager(this); connect(cityGuideNetworkAccessManager, SIGNAL(finished(QNetworkReply*)), this, SLOT(httpReadyRead(QNetworkReply*))); QNetworkRequest cityRequest(url); cityGuideNetworkAccessManager->get(cityRequest); } void CityBook:

How to change QJsonObject value in a QJson hierarchy without using copies?

陌路散爱 提交于 2019-12-04 23:02:26
I am currently using Qt5.0 with the core QJson library to handle some data for the program I am developing. To set the scene for this question I will provide you with some JSON data that illustrates my problem: { "CLOCKS": [ { "ID": "clk", "MAX": 2e+08, "MIN": 1e+07, "VALUE": "no_clock" }, { "ID": "memclk", "MAX": 2e+08, "MIN": 1e+07, "VALUE": "memclk" } ] } Here we have a parent QJsonObject containing a single key 'CLOCKS'. The value for this key is a QJsonArray of QJsonObjects that contain a number of key/value pairs that contain my data. If I wanted to retrieve the QJsonObject with id 'clk'

How to serialize to JSON in Qt

你说的曾经没有我的故事 提交于 2019-12-03 06:22:27
How can I JSON serialize a QVariant (or other type of data) in Qt. I don't want to use an external third party library like QJson Just to mention, as of Qt5, JSON is officially supported: JSON Support in Qt QVariant id(1), name("John Doe"); QJsonObject json; json["Name"] = name.toString(); json.insert("id", id.toInt()); chalup Parsing JSON with QT using standard QT library . BTW: why don't you want to use QJson? It nicely encapsulates all the QScriptValueIterator stuff, making your code easier to read. See this JSON Save Game example on serialization of an object to a JSON document. There are

利用JSON数据动态创建QtPropertyBrowser

旧时模样 提交于 2019-12-01 16:23:20
QT5支持JSON处理,但离Realse还会有些日子,所以选择QJson,用QJson处理JSON数据很严格,对象属性名称必须加双引号,否则会抛出格式不正确的错误信息。因为JSON格式能描述的数据类型有限,所以只处理整型,字符串,数字,数组,布尔,对象这几种数据类型。 下面就是利用JSON数据态创建QtPropertyBrowser。 { "encoding" : "UTF-8", "plug-ins" : [ "python", "c++", "ruby" ], "indent" : { "length" : 3, "use_space" : true, "orientation":["Left","Right","Center","Bottom"] } } 效果: 来源: oschina 链接: https://my.oschina.net/u/69166/blog/78163

easiest way to parse JSON in Qt 4.7

和自甴很熟 提交于 2019-11-28 17:51:26
I need to parse JSON object through Qt. What is the easiest/fastest way to do it? Etienne Savard Try QJson . QJson is actively developed (and used by KDE, if I'm not mistaken). The best is to checkout the source code directly and built it yourself. There is no dependencies to QJson (except for Qt and CMake). It's pretty simple to use too, have a look at some usage examples : http://qjson.sourceforge.net/usage/ JSON parsing is now supported in Qt 5. Here's how to load and parse a document: #include <QByteArray> #include <QFile> #include <QJsonObject> #include <QJsonDocument> // ... // Read JSON

easiest way to parse JSON in Qt 4.7

孤街浪徒 提交于 2019-11-27 11:04:37
问题 I need to parse JSON object through Qt. What is the easiest/fastest way to do it? 回答1: Try QJson. QJson is actively developed (and used by KDE, if I'm not mistaken). The best is to checkout the source code directly and built it yourself. There is no dependencies to QJson (except for Qt and CMake). It's pretty simple to use too, have a look at some usage examples : http://qjson.sourceforge.net/usage/ 回答2: JSON parsing is now supported in Qt 5. Here's how to load and parse a document: #include