O'Reilly logo

JavaScript JSON Cookbook by Ray Rischpater

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Parsing JSON using Qt

The Qt implementation of JSON parsing is actually quite similar in its interface to the Android version. Qt defines the QJsonObject and QJsonArray classes, which can contain JSON maps and JSON arrays respectively. The parsing itself is done by the QJsonDocument class, which has a static fromJson method that accepts JSON and performs the necessary parsing.

How to do it…

Here's a simple example:

QString json = "{ 'call': 'kf6gpe-7', 'lat': 37.40150, 'lng': -122.03683, 'result': 'ok'}";
QJsonDocument document = QJsonDocument.fromJson(json);
QJsonObject data = document.object;
QString call = data["call"].toString();

How it works…

The parsing is two-step: first, the code parses the JSON using QJsonDocument and then uses the resulting ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required