Cocos2d-x 3.0 加入了rapidjson库用于json解析。位于external/json下。
rapidjson 项目地址:http://code.google.com/p/rapidjson/
wiki:http://code.google.com/p/rapidjson/wiki/UserGuide
使用rapidjson解析json串
-
引入头文件
12#include "json/rapidjson.h"
#include "json/document.h"
-
json解析
@H_502_55@ 2345678910111213std::string str =
"{\"hello\" : \"word\"}"
;
CCLOG(
"%s\n"
,str.c_str());
rapidjson::Document d;
d.Parse<0>(str.c_str());
{
CCLOG(
"GetParseError %s\n"
,d.GetParseError());
}
if
(d.IsObject() && d.HasMember(
"hello"
)) {
}
打印结果
@H_502_55@
3
cocos2d: {
"hello"
:
"word"
}
cocos2d: word