String 2 Json test

   Json::Value root;
    root["enabled"] = true;
    root["nodeName"] = "master";
    root["serverNo"] = 354;
    root["serverType"] = "QUOTATION_SERVER";
    root["serviceCategory"] = "STOCK";
    root["version"] = 1;
    std::string strSend = root.toStyledString();

    std::string strSend ="{ "enabled": true, "nodeName": "master", "serverNo": 354, "serverType": "QUOTATION_SERVER", "serviceCategory": "STOCK", "version": 1}";
 
 
 
    Json::Reader reader;
    Json::Value root;
    memset(buf,0,128);
    lseek(fd, 0L, SEEK_SET);
    int iRead = read(fd, buf, nSize);
    if (iRead != nSize)
    {
 
    }
   
    if (reader.parse(buf, root))
    {
        m_type = root["Type"].asInt();
        m_strIp = root["ServerIp"].asString();
        m_nPort = root["Port"].asInt();
        m_strMainConfig = root["Main_Config"].asString();
        m_strStandbyConfig = root["Standby_Config"].asString();
        m_strUseConfig = root["Use_Config"].asString();
        m_nId = root["Server_id"].asInt();
    }
原文地址:https://www.cnblogs.com/132818Creator/p/14349095.html