JSCONCPP

来源:互联网 发布:iphone5c支持4g网络吗 编辑:程序博客网 时间:2024/06/06 22:13
#include <json/json.h>

字符串转jscon
    Json::Reader reader;  

    Json::Value root;  

    if (reader.parse(str, root))  // reader将Json字符串解析到root,root将包含Json里所有子元素  
    {  

        std::string upload_id = root["uploadid"].asString();  // 访问节点,upload_id = "UP000000"  
        int code = root["code"].asInt();    // 访问节点,code = 100 
    }  


jscon 到字符串

#include <json/json.h>

        Json::Value root; // Json::Value是一种很重要的类型,可以代表任意类型。如int, string, object, array         
        root["date"] = "2011-11-11";  
        root["time"] = "11:11:11";  
        Json::FastWriter writer;  
        std::string strWrite = writer.write(root);
1 0