Reading JSON data files

JSON stands for JavaScript Object Notation. It is a very light and easily consumable way of packing your data. Thanks to the CJSONDeserializer library, reading in JSON files is as simple as reading in PLIST files. In the following scene, we see a grassy field with a cat and a few trees:

Reading JSON data files

Getting ready

Please refer to the project RecipeCollection01 for full working code of this recipe.

How to do it...

Execute the following code:

#import "ActualPath.h" @implementation Ch2_ReadingJsonFiles -(CCLayer*) runRecipe { //Initialize a read-only dictionary from our file NSString *fileName = @"scene2.json"; NSString *jsonString = [[[NSString ...

Get Cocos2d for iPhone 1 Game Development Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.