0

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?

1 Answer 1

1

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);
Sign up to request clarification or add additional context in comments.

2 Comments

Only one issue: You should check if jsonDict is nil, and, if so, log e and take an error path.
@HotLicks: Yes, i already do the checking because if its nil it will crash.Thanks...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.