During project interaction with the server, json Parsing is often required. If someone wants to parse JSON, JSONKit can be a good choice.
You can download JSONKit from gitHub at: JSONKit
After the project is added, set JSONKit to a mode that does not support arc.
Then, modify the two places at the point m. <喎?http: www.bkjia.com kf ware vc " target="_blank" class="keylink"> VcD4KPHA + placement = "brush: java;"> // array-> isa = _ JKArrayClass; object_setClass (array, _ JKArrayClass); // dictionary-> isa = _ JKDictionaryClass; object_setClass (dictionary, _ JKDictionaryClass );This is because isa has been deprecated. Therefore, call the object_setClass () and object_getClass () functions.
Two json strings are set here for your reference.
Arr. conf
[{"preview_sub": "adornment_fly_1_100.png", "width": "300", "path": "adornment_fly_1.png", "name": "adornment_fly_1.png", "height": "300"}, {"preview_sub": "adornment_fly_2_100.png", "width": "300", "path": "adornment_fly_2.png", "name": "adornment_fly_2.png", "height": "300"}]
Dict. conf
{"status": "ok", "after": "14851", "before": "11011"}
NSString * res = nil; // array to json string NSArray * arr = [[NSArray alloc] initWithObjects: @ "One", @ "Two", @ "Three ", nil]; res = [arr JSONString]; NSLog (@ "res = % @", [NSString stringWithString: res]); // dictionary type (object) convert the json string NSArray * arr1 = [NSArray arrayWithObjects: @ "dog", @ "cat", nil]; NSArray * arr2 = [NSArray arrayWithObjects: [NSNumber numberWithBool: YES], [NSNumber numberWithInt: 30], nil]; NSDictionary * dic = [NSDictionary dictionaryWithObjectsAndKeys: arr1, @ "pets", arr2, @ "other", nil]; res = [dic JSONString]; NSLog (@ "res = % @", [NSString stringWithString: res]); // json string to array NSString * arrConf = [[NSString alloc] handler: [[NSBundle mainBundle] pathForResource: @ "arr" ofType: @ "conf"] encoding: NSUTF8StringEncoding error: nil]; NSArray * ConfArr = [arrConf objectFromJSONString]; NSLog (@ "% @", ConfArr); // json string to dictionary NSString * dicConf = [[NSString alloc] initWithContentsOfFile: [[NSBundle mainBundle] pathForResource: @ "dict" ofType: @ "conf"] encoding: NSUTF8StringEncoding error: nil]; NSArray * ConfDic = [dicConf objectFromJSONString]; NSLog (@ "% @", ConfDic );