JsonCPP 사용법

OpenJR·2022년 11월 21일
0

Json::Value

Json::Value 객체에 값을 입력해 저장해둘 수 있다.

Json::Value epl_table;
epl_table["team"] = "arsenal";
epl_table["played"] = 21;

Json::Value root;
root["Manager"] = "Mikel Arteta";
root["Captain"] = "N/A";
root["Vice_Captain"] = "Alexandre Lacazette";
epl_table["squad"] = root;

or

epl_table["squad"]["Manager"] = "Mikel Arteta";
epl_table["squad"]["Captain"] = "N/A";
epl_table["squad"]["Vice_Captain"] = "Alexandre Lacazette";

epl_table["record"].append("2003-04");
epl_table["record"].append("2001-02");
epl_table["record"].append("1997-98");

Json::Reader

Json데이터를 Json::Value 객체에 파싱해줄 수 있다.

std::string data;
Json::Reader reader;
Json::Value root;
reader.parse(data, root);

Json::FastWriter

Json::Value 객체의 데이터를 std::string 객체로 파싱해줄 수 있다.

Json::FastWriter fastWriter;
std::string output = fastWriter.write(root);
profile
Jacob

0개의 댓글