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?

有帮助吗?

解决方案

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);
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top