5

Im trying to use the built in JSON framework in iOS5, but i get an ARC issue when trying to compile this code:

NSDictionary *results = [jsonString JSONValue];

Is there an equivalent way to do this in iOS5, that doesn't raise an ARC issue?

ARC issue is: No visible @interface for 'NSString' declares the selector 'JSONValue'

Lahib
  • 1,305
  • 5
  • 34
  • 62
  • 1
    `NSString` does not have a method `JSONValue` maybe you have been using a category on `NSString`... is it imported? If not you need to look at [NSJSONSerialization](http://developer.apple.com/library/ios/#documentation/Foundation/Reference/NSJSONSerialization_Class/Reference/Reference.html) – Paul.s Apr 12 '12 at 11:24
  • Thank you for the help. You were right, i needed to look at the NSJSONSerialization class. – Lahib Apr 12 '12 at 11:44
  • this is what u want [Instead of Dictionary](http://stackoverflow.com/questions/18782053/nsarray-returning-string-instead-of-dictionary) – qn5566 May 11 '16 at 05:51

1 Answers1

12

The message you get means 'There is no method JSONValue declared in NSString' (which is absolutely true). In order to use the built in JSON serializer try this one:

NSError *error;
NSData *jsonData = [jsonString dataUsingEncoding:NSUTF8StringEncoding];
NSDictionary *results = [NSJSONSerialization JSONObjectWithData:jsonData options:0 error:&error];

Ps For options see the documentation on NSJSONSerialization class. Also note that results can be an NSArray as well.

Alladinian
  • 34,483
  • 6
  • 89
  • 91