How to read JSON file using NSJSONSerialization class reference?

I need to read the JSON file using the NSJSONSerialization class reference, and all the examples I found about using this class read the contents of the web page itself, instead of reading from the previously created JSON file. Does anyone know how to deal with a JSON file using this class? Thanks.

+6
source share
1 answer

A simple, quick'n'dirty example:

NSString *jsonPath = [[NSBundle mainBundle] pathForResource:@"foobar" ofType:@"json"]; NSData *data = [NSData dataWithContentsOfFile:jsonPath]; NSError *error = nil; id json = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&error]; NSLog(@"JSON: %@", json); 
+13
source

Source: https://habr.com/ru/post/915659/


All Articles