GameCorder.net

このエントリーをはてなブックマークに追加

example about array parse and create in rapidjson

This is example about parse and create array in rapid json.

json array format example


"numbers" : [1,2,3,4,5,6,7,8,9,10]
		

create interger array json


rapidjson::Document jsonDoc;
jsonDoc.SetObject();		
		
// first declare KArrayType
rapidjson::Value numbers(rapidjson::Type::kArrayType);
for(int i = 1;i <= 10;++i){
    numbers.PushBack(rapidjson::Value().SetInt(i),jsonDoc.GetAllocator());
}
rapidjson::Value key("numbers",jsonDoc.GetAllocator());
jsonDoc.AddMember(key,trumpOrder,jsonDoc.GetAllocator());
		

parse interger array json


// parse array json
for(int i = 0;i < 10;++i){
    int number = doc["numbers"][i].GetInt();
}
		

In this case deal Interger array
It have boolean and String


// bool
"bools" : [true,false,false];
// parse
for(int i = 0;i < 3;++i){
    bool flag = doc["bools"][i].GetBool();
}
// String
"strings" : ["one","two","three"];
// parse
for(int i = 0;i < 3;++i){
    string str = doc["strings"][i].GetString();
}