ข้ามไปที่เนื้อหาหลัก

บทความ

กำลังแสดงโพสต์จาก มิถุนายน, 2012

C++ JSONCPP

หลังจากทดลองใช่ ๋json_spirit (จากบทความ JSON Spirit ) มาซักพัก ผลคือใช้งานได้ดีทีเดียว แต่ตัว ่json_spirit เองก็ยังใช้งานซับซ้อนอยู่มากกว่าจะเข้าถึงข้อมูลได้ในแต่ละลำดับ ส่วน ๋JSONCPP นั้นมีการโอเวอร์โหลดโอเปอร์เรเตอร์ไว้หลายตัว ทำให้ใช้งานได้ง่ายขึ้น ทดลองเอา ตัวอย่างเดิมมาเขียนใหม่ #include <iostream> #include <string> using namespace std; #include <jsoncpp/json/reader.h> int main(){     std::string json_str = "{\"a man\":{\"name\":\"a man\",\"age\":25},\"a boy\":{\"name\":\"a boy\", \"age\":15}}";     cout << "The JSON string: " << json_str << endl;     Json::Value root;     Json::Reader reader;     cout<<"Read JSON string: "<<reader.parse(json_str, root)<<endl;     for(Json::ValueIterator i = root.begin(); i != root.end(); i++){         auto key = i.key().asString();         cout << "Key: