json库使用问题积累

1、类型不同解析结果不同,尤其是Unsigned int 和int 是2种类型

Json::Value v;

// v["test"][(unsigned int)0] = 2147488992; // 编译不过

v["test"][(unsigned int)0]  = (int)2147488992;

v["test"][(unsigned int)1] = (unsigned int)2147488992;

 

std::string s;

Json::FastWriter w(s);

if (w.write(v))

{

     Json::Value v2;

     Json::Reader r;

     if (r.parse(s, v2, false))

     {

            int n = v["test"].size();

           for(unsigned int i=0;  i< n; i++)

          {

                   int  nValue = v["test"][i].asint;             ///       ------------------------[1]

                  printf("%d   :   %ld !\n", i, nValue);

          }

     }
}

输出:

0    : 2147488992(对应的负数)

0    : 0(对应的负数)

如果【1】改为int  nValue = v["test"][i].asUint; 

0    : 0(对应的负数)

0    : 2147488992(对应的负数)

 

发布了35 篇原创文章 · 获赞 5 · 访问量 18万+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章