문제

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