Json(json解析)

探讨了Cocos2d-x引擎中JSON解析的相关技术,包括JSON类型定义、JSON结构体设计、创建与销毁JSON对象的方法,以及获取JSON对象属性的函数。

         cocos2dx json解析         


#ifndef SPINE_JSON_H_

#define SPINE_JSON_H_


namespace cocos2d { 


namespace extension {


/* Json Types: */

#define Json_False 0

#define Json_True 1

#define Json_NULL 2

#define Json_Number 3

#define Json_String 4

#define Json_Array 5

#define Json_Object 6


//json 结构体

typedef structJson {

struct Json* next;

struct Json* prev;//next/prev allow you to walk array/object chains(链条). Alternatively(或者), use getSize/getItemAt/getItem 

struct Json* child; //An array or object item will have a child pointer pointing to a chain of the items in the array/object. 


int type;//The type of the item, as above. 


const char* valuestring;//The item's string, if type==Json_String 

int valueint;//The item's number, if type==Json_Number 

float valuefloat;//The item's number, if type==Json_Number 


const char* name;//The item's name string, if this item is the child of, or is in the list of subitems of an object. 

}Json;


//Supply(供给) a block(块) of JSON, and this returns a Json object you can interrogate(询问). Call Json_dispose when finished. 

Json*Json_create (const char* value);


//Delete a Json entity and all subentities. 

voidJson_dispose (Json* json);


//Returns the number of items in an array (or object). 

intJson_getSize (Json* json);


// Retrieve(检索) item number "item" from array "array". Returns NULL if unsuccessful. 

Json*Json_getItemAt (Json* json, int item);


//Get item "string" from object. Case insensitive. 

Json*Json_getItem (Json* json, const char* string);

const char*Json_getString (Json* json, const char* name, const char* defaultValue);

floatJson_getFloat (Json* json, const char* name, float defaultValue);

intJson_getInt (Json* json, const char* name, int defaultValue);


//For analysing(分析) failed parses(解析). This returns a pointer to the parse error. You'll probably need to look a few chars back to make sense of it. Defined when Json_create() returns 0. 0 when Json_create() succeeds.

const char* Json_getError (void);


}} // namespace cocos2d { namespace extension {


#endif /* SPINE_JSON_H_ */


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值