Previously in the cocos2d-x project using json parsing, integrated libjson library found that most of the parsing methods provided on the Internet get value in the parsing process, and does not save the parsing results effectively, as a result, I tried to save the parsing result to an array or dictionary based on the data format.
Do not dare to exclusive, the Code is available:
JsonUtil: parseArrJSON (JSONNODE * n, CCObject ** (n = isAry = JSONNODE_ITERATOR it = * key = json_name (* (strcmp (key ,) = * obj = (it! = (* It = (json_type (* it) = * char_str = CCString: ccs (*) * obj)-> key = json_name (*! *) * Obj)-> (json_type (* it) = JSON_ARRAY | json_type (* it) = * tempobj = * it, & *) * obj) -> key = json_name (*! *) * Obj)-> (json_type (* it) = * value = json_as_string (** char_str = *) * obj)-> key = json_name (*! *) * Obj)-> (json_type (* it) = json_number value = json_as_float (** char_str = CCString: createWithFormat (*) * obj) -> key = json_name (*! *) * Obj)-> + * JsonUtil: jsonValue (** an = * obj = &View Code
Create a class JsonUtil, which contains two static methods. Call JsonUtil: jsonValue (const char * _ char) when using JsonUtil. The parsed results are saved in the dictionary or array. For example:
*betem=CCArray *ary= (CCArray *) JsonUtil::jsonValue(betem);
ccout(ary);
Ccout is a custom method for printing arrays and dictionaries. The cocos2d-x's CCLog is really far behind the NSLog, even if it prints out the time.
The attached ccout code can be used to print the json data stored in CCArray or CCDictionary, barely like the NSLog output:
Ccout (CCObject * thob, donotset =, dot = AppDelegate: ccout (CCObject * thob, donotset, (dynamic_cast <CCDictionary *> <* temp = (CCDictionary *** key = ele-> * ob = ele-> <(I =; I <donotset +; I ++) cout <key <-> ccout (ob, donotset + <(I =; I <donotset; I ++) cout <(dynamic_cast <CCArray *> <* temp = (CCArray ** (dynamic_cast <CCDictionary *> (ob! = Temp-> ccout (ob, donotset +,-> ccout (ob, donotset + (dynamic_cast <CCArray *>-> ccout (ob, donotset + (dynamic_cast <CCString *> <(CCString *) ob)-> (ob! = Temp-> <View Code
Output result:
======