JSON parsing scheme, json Parsing
In iOS, there are four common JSON resolution solutions.
Third-party frameworks: JSONKit, SBJson, and TouchJSON (performance from left to right, the worse)
Apple native (built-in): NSJSONSerialization (Best Performance)
Conversion between JSON and OC
JSON-> OC object
NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&error];
Use this class to parse the first parameter data in json format,
The second parameter: Operation: Generally, NSJSONReadingMutableContainers or kNilOptions is written. The latter has the highest efficiency. The former requires a variable container.
Third parameter: Incorrect address
OC Object> JSON
NSData *data = [NSJSONSerialization dataWithJSONObject:@{@"name":@"jack"}] options:NSJSONWritingPrettyPrinted error:nil];
To Format JSON data, you can write it to a plist file.
// Parse JSON NSDictionary * dict = [NSJSONSerialization JSONObjectWithData: data options: kNilOptions error: nil]; [dict writeToFile: @ "/Users/DDZ/Desktop/data. plist "atomically: YES];