2

I am receiving this JSON string and want to know how to serialize it into a dictionary so that I can parse it into a managed object.

I have looked at a few ways (named in the title), and can't seem to find the simplest, quickest alternative. I would like to use NSJSONSerialization, but I'm not sure it is made to do this?

Code where string comes in

NSString *data = [[NSString alloc]initWithData:response encoding:NSUTF8StringEncoding];
        NSLog(@"String %@",data);

NSLog message

String [{"0":"1","id":"1","1":"re ee","name":"re ee","2":"http:\/\/ree.com\/images\/re.png","backgroundImageUrl":"http:\/\/ree.com\/images\/re.png","3":"http:\/\/ree.com\/images\/re.png","logoImageUrl":"http:\/\/ree.com\/images\/re.png"}]<br />

Thank you in advance

William Falcon
  • 9,813
  • 14
  • 67
  • 110
  • 1
    Both are reasonably solid. (Truth be told, SBJSON has more "burn in" time, but NSJSONSerialization has Apple behind it.) In part it simply has to do with which is more convenient. With SBJSON you work with NSStrings, while with NSJSONSerialization you work with NSData, plus a few minor operational differences. I wouldn't bother with any of the others. – Hot Licks Apr 09 '13 at 01:37
  • So I'm using AFNetworking which apparently uses NSStrings? – William Falcon Apr 09 '13 at 01:38
  • Well, in your above example `response` is NSData, I assume. – Hot Licks Apr 09 '13 at 01:51

1 Answers1

1

JSONKit is what your are looking for.

Besides the ease of use, it's quicker than SBJSon, even quicker than NSJSONSerialization.

For your example, your can get an array like this:

NSArray* arrayFromJson = [data objectFromJSONString];
NSString* id = arrayFromJson[0][@"id"];

Easy, huh?

MasterBeta
  • 606
  • 6
  • 15
  • 2
    NSJSONSerialization is perfectly fine. JSONKit has a potential issue - due to its use of deprecated functions. It's not that much faster than NSJSONSerialization anymore since the Apples parser became faster. – CouchDeveloper Apr 09 '13 at 15:55
  • 1
    Can anyone provide any insight on how the parsing speeds are now? Last update of the `Readme.md` on GitHub is 2 years old. I wonder how things are now. – Majster May 04 '14 at 10:44
  • NSJSONSerialization all the way – William Falcon Feb 06 '15 at 13:01