菜鸟笔记
提升您的技术认知

rapidjson 构造数组-ag真人游戏

构造示例:

{
    "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;
}
网站地图