Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

easiest way to parse JSON in Qt 4.7

I need to parse JSON object through Qt. What is the easiest/fastest way to do it?

like image 950
wael34218 Avatar asked Nov 12 '10 23:11

wael34218


People also ask

Is JSON fast to parse?

In any case, to answer my own question, it seems that parsing JSON should take about 8 cycles per input byte on a recent Intel processor. Maybe less if you are clever. So you should expect to spend 2 or 3 seconds parsing one gigabyte of JSON data.

What are the methods to parse JSON?

parse() The JSON. parse() method parses a JSON string, constructing the JavaScript value or object described by the string. An optional reviver function can be provided to perform a transformation on the resulting object before it is returned.

How do I parse JSON in Powerautomate?

Using 'parse JSON' action Instead of select operator, if you want to get multiple values from JSON like more than 3 or 4 then we can achieve it using 'Parse JSON' which is a standard connector. Configure parse JSON accordingly. The value of content will be the 'body' value from 'Send an HTTP request to SharePoint.


2 Answers

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 file QFile file("/path/to/file.json"); file.open(QIODevice::ReadOnly); QByteArray rawData = file.readAll();  // Parse document QJsonDocument doc(QJsonDocument::fromJson(rawData));  // Get JSON object QJsonObject json = doc.object();  // Access properties qDebug() << json["something"].toString(); 
like image 114
laurent Avatar answered Nov 08 '22 11:11

laurent


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/

like image 20
Etienne Savard Avatar answered Nov 08 '22 10:11

Etienne Savard