Something about Parsing JSON with QT and VS2010
-
@
QScriptValue value;
QScriptEngine engine;
QByteArray enUrl = "http://mobilecdn.kugou.com/new/app/i/search.php?keyword=walking&cmd=300&pagesize=100";
QNetworkReply *reply = manager->get(QNetworkRequest(QUrl(enUrl)));
QByteArray musicJson = reply->readAll();
value =engine.evaluate("(" + QString(musicJson) + ")");
@the problem is :
musicJson have data, but when I parsing, the value is empty;
do somebody have the same problem? -
Hi, ~dev_jiang!
Evaluating JSON with QScriptEngine is not the best idea. If to be honest - it's a bad practise. Why is? Just cos it takes too much memory. Use it only if you need to evaluate JavaScript code, not it's notation.
There is one of my favourite libraries - QJson. It allows to work with JSON on the QVariant* level. Read, write, serialize, etc.
Project link: http://qjson.sourceforge.net/