I am new to rapidjson. I have test.json that contains {"points": [1,2,3,4]}
and I use the following code to get the "points" array data
std::string fullPath = CCFileUtils::sharedFileUtils()->fullPathForFilename("json/deluxe/treasurebag.json"); unsigned long bufferSize = 0; const char* mFileData = (const char*)CCFileUtils::sharedFileUtils()->getFileData(fullPath.c_str(), "r", &bufferSize); std::string clearData(mFileData); size_t pos = clearData.rfind("}"); clearData = clearData.substr(0, pos+1); document.Parse<0>(clearData.c_str()); assert(document.HasMember("points")); const Value& a = document["points"];
and its result
Cocos2d: a[0] = 1 Cocos2d: a[1] = 2 Cocos2d: a[2] = 3 Cocos2d: a[3] = 4
as was expected. But now when I try to get data (get x and y ) from an array like this
{"points": [{"y": -14.25,"x": -2.25},{"y": -13.25,"x": -5.75},{"y": -12.5,"x": -7.25}]}
An error has occurred and is thrown to the compiler:
//! Get the number of elements in array. SizeType Size() const { RAPIDJSON_ASSERT(IsArray()); return data_.a.size; }
Can someone explain what I did wrong or missed something? Sorry for my bad english.
Any help would be appreciated.
Thanks.
source share