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?

Was it helpful?

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);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top