Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
828 views
in Technique[技术] by (71.8m points)

iphone - JSONValue ARC issue

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'

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...