原文地址:http://www.jb51.cc/article/p-rhfkjoll-sg.html
cocos2dx 2.2.x 版本以后,使用rapidjson进行数据解析,因为的效率要高写,下面是一个解析事例:
ball.json 数据如下:
- {
- "entities":[
- {
- "entity":{
- "TapOpposite":0,
- "Interval":0.95,
- "BallNum":1
- }
- },248); line-height:17.600000381469727px; margin:0px!important; padding:0px 3px 0px 10px!important"> {
- "entity":{
- "TapOpposite":0,108); list-style:decimal-leading-zero outside; color:inherit; line-height:17.600000381469727px; margin:0px!important; padding:0px 3px 0px 10px!important"> "Interval":0.91,248); line-height:17.600000381469727px; margin:0px!important; padding:0px 3px 0px 10px!important"> "BallNum":2
- }
- },108); list-style:decimal-leading-zero outside; color:inherit; line-height:17.600000381469727px; margin:0px!important; padding:0px 3px 0px 10px!important"> "BallNum":3
- ]
- }
在cocos2dx中json的读取是用的rapidjson,包含在libExtensions的CocoStudio的Json下:
所以在使用前我们需要引用命名空间和头文件:
#include "cocos-ext.h"
USING_NS_CC_EXT;
using namespace rapidjson;