c++ - JSON parsing with Qt -



c++ - JSON parsing with Qt -

hei , have text in json : ( without returns in 1 line)

[ { "error":false, "username":"benutzer", "format":"human", "latitude_min":84, "latitude_max":36, "longitude_min":5, "longitude_max":20, "records":203 }, [ { "mmsi":233434540, "time":"2014-10-09 06:19:06 gmt", "longitude":8.86037, "latitude":54.12666, "cog":347, "sog":0, "heading":236, "navstat":0, "imo":0, "name":"helgoland", "callsign":"dk6068", "type":90, "a":20, "b":15, "c":4, "d":4, "draught":2, "dest":"bremerhaven", "eta":"00-00 00:00" }, { "mmsi":319072300, "time":"2014-10-09 06:08:53 gmt", "longitude":9.71578, "latitude":54.31949, "cog":343.6, "sog":0, "heading":197, "navstat":5, "imo":1012189, "name":"m.y. ester iii", "callsign":"zged3", "type":37, "a":31, "b":35, "c":7, "d":6, "draught":3.5, "dest":"schact audorf", "eta":"09-16 08:00" } // many more lines json valid. ] ]

i parse , set in mysql table. not all, name , mmsi first. don't view in consle because dont jump in foreach:

bool ok = true; // json info in reply & ok boolean qvariantlist result = parser.parse(reply, &ok).tolist(); foreach(qvariant record, result) { qvariantmap map = record.tomap(); qdebug() << map.value("name"); }

what's wrong ? when debug, see doesn't jump in foreach. utilize qjson libary : qjson::parser parser; please can tell me wrong?

your code looks iterating on top level array, while info looking in nested array, sec item of top level array. so, need iterate on items in inner array.

the next code works me sample json:

qvariantlist result = parser.parse(reply, &ok).tolist().at(1).tolist(); foreach (const qvariant &item, result) { qvariantmap map = item.tomap(); qdebug() << map["name"].tostring(); qdebug() << map["mmsi"].tolonglong(); }

c++ mysql json qt parsing

Comments

Popular posts from this blog

xslt - DocBook 5 to PDF transform failing with error: "fo:flow" is missing child elements. Required content model: marker* -

mediawiki - How do I insert tables inside infoboxes on Wikia pages? -

Local Service User Logged into Windows -