I have a C++11 code that takes a couple of Jsons and changes the format. In this procedure I want to construct a Json::Value object that has the following structure:
{ <int value>: [<int value>, <string value>, <string value>, <string value>] }
I do this in the following loop:
for(Json::Value::ArrayIndex ic = 0; ic != yd.size(); ic++){
Json::Value nn(Json::arrayValue);
nn.append(yd[ic]["CHANNEL_ID"].asInt ());
nn.append(yd[ic]["tech" ].asString());
nn.append(yd[ic]["file" ].asString());
nn.append(yd[ic]["data" ].asString());
Json::Value mm;
mm[yd[ic]["CHANNEL_ID"].asInt()] = nn;
afnew.append(mm);
}
Here yd is the json that I read from, and I want to append everything to afnew. The node CHANNEL_ID is a large number (I may even consider using unsigned longs here, but anyway). The output is ok BUT it appends a lot of nulls in front of the actual array. Essentially, if the channel number is 500, it will append 499 nulls in front of it. If I convert the channel number to string and use this as key for the mm json, it works (also forcing the mm to Json::objectValue). Is there a way around using strings here as keys, or will the integer values always be interpreted as vector indices?
Thank you for any advice and regards!
c.
Aucun commentaire:
Enregistrer un commentaire