jsoncpp的简单使用

来源:互联网 发布:淘宝分析软件 编辑:程序博客网 时间:2024/06/07 15:07

1.之前我们编译好了jsoncpp了

 

2.现在使用

 

#include <stdio.h>#include <json/json.h>#include <string>using namespace std;int main(int argc, char **argv) {Json::Value root;Json::Value arrayObj;Json::Value item;for(int i=0;i<5;i++){char buffer[20];sprintf(buffer,"key%d",i);item[buffer] = i;arrayObj.append(item);}root["key1"] = "value1";root["key2"] = "value1";root["array"] = arrayObj;//生成string jsonstd::string out = root.toStyledString();std::cout << out << std::endl;//一些有用的apistd::cout << root.size() <<std::endl;;std::cout << root.removeMember("key2") <<std::endl;;std::cout << root.toStyledString() <<std::endl;;for(;;);return 1;}


0 0