Reputation: 413
I am trying to create a json cpp array and populate it with data in a std::vector.
My code looks like this
void
Box_20::BuildCommitUploadPostData(const PartInfoColl& partColl)
{
Json::Value parts;
parts["parts"] = Json::arrayValue;
int idx = 0;
for (const auto& p : partColl) {
Json::Value partInfo;
partInfo["part_id"] = p.partId;
partInfo["offset"] = p.offset;
partInfo["size"] = p.size;
parts[idx]["part"] = partInfo;
idx++;
}
/// do more stuff here
}
However when I run it, it bombs out.
I can;t see what I am doing wrong here.
Upvotes: 2
Views: 2498
Reputation: 413
This worked.
void DoSOmeJsonStuff(const PartInfoColl& partColl)
{
Json::Value parts;
int idx = 0;
for (const auto& p : partColl) {
Json::Value partInfo;
partInfo["part_id"] = p.partId;
partInfo["offset"] = p.offset;
partInfo["size"] = p.size;
parts[idx]["part"] = partInfo;
idx++;
}
Json::Value root;
root["parts"] = parts;
/...
}
Upvotes: 4