Question

I just try to deploy client server apps in Objective-C. I get an json string like this from server when I make a query:

@"{"url":"http://my-company.com/json"}".

How do I extract the http://my-company.com/json directly using Objective C?

Était-ce utile?

La solution

Read more about NSJSONSerialization

NSString *jsonString = @"{\"url\":\"http://my-company.com/json\"}";
NSData *jsonData = [jsonString dataUsingEncoding:NSUTF8StringEncoding];

NSError *e;
NSDictionary *jsonDict = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:&e];
NSString *url = [jsonDict objectForKey:@"url"];
NSLog(@"url: %@", url);
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top