jsoncpp的简单使用
发布时间:2020-12-16 19:37:27 所属栏目:百科 来源:网络整理
导读:1.之前我们编译好了jsoncpp了 2.现在使用 #include stdio.h#include json/json.h#include stringusing namespace std;int main(int argc,char **argv) {Json::Value root;Json::Value arrayObj;Json::Value item;for(int i=0;i5;i++){char buffer[20];sprint
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 json std::string out = root.toStyledString(); std::cout << out << std::endl; //一些有用的api std::cout << root.size() <<std::endl;; std::cout << root.removeMember("key2") <<std::endl;; std::cout << root.toStyledString() <<std::endl;; for(;;); return 1; }
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |