构造示例:
{
"userlist": [
{
"userid" : 20,
"productidlist" : [1, 2],
},
{
"userid" : 21,
"productidlist" : [1, 2]
}
]
}
代码示例:
#include "rapidjson/writer.h"
#include "rapidjson/stringbuffer.h"
#include
using namespace rapidjson;
using namespace std;
int main() {
stringbuffer s;
writer writer(s);
writer.startobject();
writer.key("userlist");
writer.startarray();
writer.startobject();
writer.key("userid");
writer.uint(20);
writer.key("productidlist");
writer.startarray();
for (unsigned i = 1; i < 3; i )
writer.uint(i);
writer.endarray();
writer.endobject();
writer.startobject();
writer.key("userid");
writer.uint(21);
writer.key("productidlist");
writer.startarray();
for (unsigned i = 1; i < 3; i )
writer.uint(i);
writer.endarray();
writer.endobject();
writer.endarray();
writer.endobject();
cout << s.getstring() << endl;
}