PDA

View Full Version : JSON - depth problem, map changes to list (QVariantList instead of QVariantMap)



null123
16th May 2010, 17:53
{
"test1":{
"test2":[[3,5,2,1,11,9],[8,4,1,2,18,7],[6,6,3,1,11,15],[0,11,3,4,11,11],[3,11,3,4,21,6],
[6,11,3,4,21,11],[20,0,4,3,10,6],[128,0,2,2,16,9],[0,0,4,4,6,2],[8,0,5,4,24,2],[8,6,5,5,24,14],
[0,6,4,5,6,14],[1,4,2,2,7,6],[1,4,2,2,7,8],[1,4,2,2,7,10],[1,4,2,2,7,12],[1,4,2,2,26,6],
[1,4,2,2,26,8],[1,4,2,2,26,10],[1,4,2,2,26,12],[4,1,4,2,10,3],[4,1,4,2,14,3],[4,1,4,2,18,3],
[4,1,2,2,22,3],[4,1,4,2,10,16],[4,1,2,2,14,16],[4,1,2,2,18,16],[4,1,4,2,20,16],[5,8,2,2,16,16]],
[...]
How i can push test2 into QMap<int,QMap<int,int> > (QMap<id_of_row,QMap<id_of_row2,number_value>>)?
I tried QJson:

QJson::Parser p;
QMap<QString,QVariant> res = p.parse(str.toLatin1()).toMap();

QMap<QString,QVariant> test1 = res["test1"].toMap();

QMap<QString,QVariant> test2 = test1["test2"].toMap();
But test2.count() = 0. Type of res[test1] is QVariantMap, test1[test2] is QVariantList. How to repair it? Maybe there is a better way to do it in Qt? I've also tried QScriptEngine, but it always returned parsing error.

Compilable example: http://rapidshare.com/files/388038949/temp.rar.html