-
大小: 660KB文件類型: .tar金幣: 1下載: 0 次發(fā)布日期: 2021-06-11
- 語言: 其他
- 標(biāo)簽: jsoncpp??例子??靜態(tài)庫(kù)??
資源簡(jiǎn)介
jsoncpp一個(gè)讀取例子,內(nèi)含jsoncpp靜態(tài)庫(kù)和include,不需安裝jsoncpp,編譯命令見make文件。
代碼片段和文件信息
//?g++?-g?-Wall?-o?test_json?test_json.cpp?-I./include?-L./lib?-ljson
#include?
#include?“json/json.h“
using?namespace?std;
int?main()?{
{
??//?one?data
??cout?<??string?test?=?“{\“id\“:1\“name\“:\“hello\“}“;
??Json::Reader?reader;
??Json::Value?value;
??if?(reader.parse(test?value))?{
????int?id?=?value[“id“].asInt();
????string?name?=?value[“name“].asString();
????cout?<??}?else?{
????cout?<“parse?error“?<??}
}
{
??//?more?data
??cout?<??string?test?=?“{\“array\“:[{\“id\“:1\“name\“:\“hello\“}{\“id\“:2\“name\“:\“world\“}]}“;
??Json::Reader?reader;
??Json::Value?value;
??if?(reader.parse(test?value))?{
????const?Json::Value?arrayObj?=?value[“array“];
????for?(size_t?i=0;?i ??????int?id?=?arrayObj[i][“id“].asInt();
??????string?name?=?arrayObj[i][“name“].asString();
??????cout?<????}
??}?else?{
????cout?<“parse?error“?<??}
}
??return?0;
}
評(píng)論
共有 條評(píng)論