最新由於用戶端要用到jsoncpp,所以自己也跟著項目的需求學了一下jsoncpp.以前沒用過xml,但是感覺接觸json後,還蠻好用的。
參考地址 http://jsoncpp.sourceforge.net/class_json_1_1_value.html
#include <QtCore/QCoreApplication>
#include <json/json.h>
#include <string>
using std::string;
int main(int argc, char *argv[])
{
Json::Reader reader;
Json::Value json_object;
const char* json_document = "{/"age/" : 26,/"person/":[{/"id/":1,/"study/":[{/"language/":/"chinese/"}],/"name/":/"chen/"},{/"id/":2,/"name/":/"zhang/"}],/"name/" : /"huchao/"}";
if (!reader.parse(json_document, json_object))//讀入字串,然後轉換成json格式
return 0;
int a1=0;
json_object["name"] ="wang";//修改資料
json_object["person"][a1]["study"][a1]["language"] = "English";
std::cout << json_object["name"] << std::endl;//讀取資料
std::cout << json_object["person"][a1]["study"][a1]["language"]<< std::endl;
std::cout << json_object["age"] << std::endl;
Json::Value json_object;
json_object.append("11"); //加入數組格式
json_object.append("12");
json_object.append("13");
return a.exec();
}
要下載jsoncpp,然後程式包含jsoncpp源碼。