Click here to Skip to main content
15,917,610 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
how to store multiple json object in one object in c++
For example
json::value obj1;
obj1["ID"]="12"
obj1["Name"]="abc"

json::value obj2;
obj2["ID"]="11"
obj2["Name"]="xyz"

I want to store the above two objects in one json object
json::value obj3;

outupt is like in below format
obj3=[{"ID":"12","Name":"abc"},{"ID":"11","Name":"xyz"}]

What I have tried:

json::value obj1;
obj1["ID"]="12"
obj1["Name"]="abc"

json::value obj2;
obj2["ID"]="11"
obj2["Name"]="xyz"


items[0] = item;

group[L"Items"] = items;

utility::stringstream_t stream;
group.serialize(stream);


json::value obj3;
obj3[0] = item;

group[L"Items"] = items;

utility::stringstream_t stream;
group.serialize(stream);
Posted
Updated 7-Jun-16 3:55am
v3

1 solution

you have different objects as obj1, obj2 and obj3. Such objects are best stored in a container object like array or vector.

C++
myarray.add(obj1);
myarray.add(obj2);
myarray.add(obj3);


For storing them you at first write the count and than every member.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900