C++ 如何使用rapidjson查看.json中的数组?(cocos2d-x)

C++ 如何使用rapidjson查看.json中的数组?(cocos2d-x),c++,cocos2d-x,rapidjson,C++,Cocos2d X,Rapidjson,我认为问题是具体的,我想遍历一个.json中的数组,其形式如下: { "N" : 5, "Rotacion" : 42, "Igual" : 20, "Inverso" : 0, "RotacionE" : 47, "Espejo" : 22, "Puntuacion" : 0, "_id" : "563b7b4756ab632f47fe6d7f" , "Lados" : [], "Camino" : [ 6, 5, 4, 21, 22, 7, 2, 3, 20, 23, 8, 1, 18,

我认为问题是具体的,我想遍历一个.json中的数组,其形式如下:

{ "N" : 5, "Rotacion" : 42, "Igual" : 20, "Inverso" : 0, "RotacionE" : 47, "Espejo" : 22, "Puntuacion" : 0, "_id" :  "563b7b4756ab632f47fe6d7f" , "Lados" : [], "Camino" : [ 6, 5, 4, 21, 22, 7, 2, 3, 20, 23, 8, 1, 18, 19, 24, 9, 0, 17, 16, 15, 10, 11, 12, 13, 14 ], "__v" : 0 }
我搜索了一些教程,他们告诉我要做以下工作:

const Value& a = document["a"];
assert(a.IsArray());
for (SizeType i = 0; i < a.Size(); i++) // Uses SizeType instead of size_t
    printf("a[%d] = %d\n", i, a[i].GetInt());


请告诉我为什么会发生错误?或者至少告诉我如何访问数组进行打印,然后对其进行操作

这是因为有两种类型具有相同的名称

要解决歧义,只需使用
rapidjson::Value
,或键入一个新名称。

string josn=“{\'N\”:5,“Rotacion\”:42,“Igual\”:20,“Inverso\”:0,“RotacionE\”:47,“Espejo\”:22,“Puntuacion\”:0,“u id\”:“563B4756AB632F476F\”,“Lados\[],“Camino\”:[6,5,4,21,22,7,2,3,20,23,8,1,18,19,24,9,0,17,16,15,10,11,12,13,14],“\uu v\:0}”;
string josn="{ \"N\" : 5, \"Rotacion\" : 42, \"Igual\" : 20, \"Inverso\" : 0, \"RotacionE\" : 47, \"Espejo\" : 22, \"Puntuacion\" : 0, \"_id\" :  \"563b7b4756ab632f47fe6d7f\" , \"Lados\" : [], \"Camino\" : [ 6, 5, 4, 21, 22, 7, 2, 3, 20, 23, 8, 1, 18, 19, 24, 9, 0, 17, 16, 15, 10, 11, 12, 13, 14 ], \"__v\" : 0 }";
    rapidjson::Document doc;
    if (!doc.Parse<0>(josn.c_str()).HasParseError()) {
        const rapidjson::Value& myArray=doc["Camino"];
        vector<int> Camino;
        if (myArray.GetType()==rapidjson::kArrayType) {
            for (int i=0; i<myArray.Size(); i++) {
                Camino.push_back(myArray[i].GetInt());
            }
            for (auto it=Camino.begin(); it!=Camino.end(); it++) {
                printf("%d\n",*it);
            }
        }

    }else{
        printf("1 error parsing the json %zu\n",doc.GetErrorOffset());
    }
rapidjson::文档文档; if(!doc.Parse(josn.c_str()).HasParseError()){ 常量rapidjson::Value&myArray=doc[“Camino”]; 矢量卡米诺; if(myArray.GetType()==rapidjson::kArrayType){ 对于(int i=0;i
 /home/jmuniz/code/Cocos2d-x/interface/cocos2d/cocos/base/CCValue.h:54:14: note: candidates are: class cocos2d::Value
  class CC_DLL Value
                ^
 In file included from /home/jmuniz/code/Cocos2d-x/interface/Classes/HelloWorldScene.cpp:4:0:
 /home/jmuniz/Dev/rapidjson-master/include/rapidjson/document.h:1758:31: note:                 typedef class rapidjson::GenericValue<rapidjson::UTF8<> > rapidjson::Value
  typedef GenericValue<UTF8<> > Value;
                                 ^
 /home/jmuniz/code/Cocos2d-x/interface/Classes/HelloWorldScene.cpp:84:7: error: ‘Value’ does not name a type
  const Value& a = d["Camino"];
FILE* fp = fopen("/home/jmuniz/code/Cocos2d-x/interface/Resources/res/puzzles(copia).json", "r"); // non-Windows use "r"
char readBuffer[65536];
FileReadStream is(fp, readBuffer, sizeof(readBuffer));
Document d;
d.ParseStream(is);
fclose(fp);
string josn="{ \"N\" : 5, \"Rotacion\" : 42, \"Igual\" : 20, \"Inverso\" : 0, \"RotacionE\" : 47, \"Espejo\" : 22, \"Puntuacion\" : 0, \"_id\" :  \"563b7b4756ab632f47fe6d7f\" , \"Lados\" : [], \"Camino\" : [ 6, 5, 4, 21, 22, 7, 2, 3, 20, 23, 8, 1, 18, 19, 24, 9, 0, 17, 16, 15, 10, 11, 12, 13, 14 ], \"__v\" : 0 }";
    rapidjson::Document doc;
    if (!doc.Parse<0>(josn.c_str()).HasParseError()) {
        const rapidjson::Value& myArray=doc["Camino"];
        vector<int> Camino;
        if (myArray.GetType()==rapidjson::kArrayType) {
            for (int i=0; i<myArray.Size(); i++) {
                Camino.push_back(myArray[i].GetInt());
            }
            for (auto it=Camino.begin(); it!=Camino.end(); it++) {
                printf("%d\n",*it);
            }
        }

    }else{
        printf("1 error parsing the json %zu\n",doc.GetErrorOffset());
    }