C++ 使用jsoncpp 封装及解析 json字符串(包含复杂数组)

C++ 使用jsoncpp 封装及解析 json字符串(包含复杂数组)

转自:https://blog.csdn.net/centnetHY/article/details/83310331?depth_1-utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-3&utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-3

#include 
#include 
#include 
using namespace std;
 
 
int main()
{
    //std::string strValue = "{\"name\":\"json\",\"array\":[{\"cpp\":\"jsoncpp\"},{\"java\":\"jsoninjava\"},{\"php\":\"support\"}]}";    
    
    // 构建json数组
    Json::Value array;
    Json::Value root;
    Json::Value person;
    
    Json::FastWriter writer;
 
 
    person["name"] = "allen";
    person["age"] = 10; 
    person["sex"] = "male";
    root.append(person);
 
    person["name"] = "keiv";
    person["age"] = 20; 
    person["sex"] = "female";
    root.append(person);
    
    person["name"] = "lihua";
    person["age"] = 10; 
    person["sex"] = "female";
    root.append(person);
 
    // 添加数组格式
    //array["array"].append(root);
    
    // 子节点挂到根节点上
    array["array"] = Json::Value(root);
 
    string data = writer.write(array);
 
    //cout<

你可能感兴趣的:(linux,c/c++)