json文件的生成

 1
//json常用于传输数据
//前往json.org下载jsoncpp文件并添加到项目
#include <stdio.h> 2 #include <string> 3 using namespace std; 4 5 /* jsoncpp support */ 6 #include "jsoncpp/json.h" // JSON构造与解析 7 8 9 int main() 10 { 11 // 构造JSON请求 12 Json::Value req; 13 req["errorCode"] = 1001; //错误码 14 req["reason"] = "OK"; 15 16 if(1) 17 { 18 Json::Value jobj; //定义对象 19 jobj["userId"] = 10099380; 20 jobj["name"] = "AAA"; 21 req["result"] = jobj; 22 } 23 if(1) 24 { 25 Json::Value jarray; //定义数组 26 jarray.append(123); 27 jarray.append(456); 28 jarray.append(789); 29 jarray.append(0); 30 req["numbers"] = jarray; 31 } 32 33 Json::FastWriter writer; 34 string jsonstr = writer.write(req); 35 36 printf("%s \n", jsonstr.c_str()); 37 return 0; 38 }

 

posted on 2017-12-13 23:51  Doctor_uee  阅读(282)  评论(0)    收藏  举报

导航