0

Possible Duplicate:
How do I parse JSON with Objective-C?

Let me first say that I am still new to Objective-C but I am looking for way to store JSON data from a restful API to a variable. I have already established a connection to the API I am just unfamiliar with the commands to search to find specific information. Any help or references would be greatly appreciated. Thanks!

6
  • Is not but this might help. I'll check it out. Thanks. Commented Jan 21, 2013 at 2:40
  • Your question is kind of ambiguous - do you need help downloading and parsing JSON? Do you need instructions on interacting with your API (is that what you mean by '...commands to search...'?)? Commented Jan 21, 2013 at 2:42
  • "I am just unfamiliar with the commands to search to find specific information" - there are no standard "JSON commands" to do anything. You can get data as a response to HTTP requests, that's it. What sort of HTTP request means what is up to the creator of the API to decide, you need to work with their documentation. Commented Jan 21, 2013 at 3:08
  • @Carl I am looking for way to interact with the API. What I am attempting to do is have some info from the API like say a username and store or show that name on a text field within an app if that makes sense. Commented Jan 21, 2013 at 3:11
  • You are looking for parsing it, as, while parsing it you can find the information of interest and pull it out, which is why I suggested it is actually a duplicate. Commented Jan 21, 2013 at 3:34

3 Answers 3

1

One of the easiest way to retrieve JSON data from a restful API is using the AFNetworking library.

Here's a sample code

NSURL *url = [NSURL URLWithString:@"http://yourAPIUrl/whatever"];
NSURLRequest *request = [NSURLRequest requestWithURL:url];

AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {
    // do whatever you like with your JSON object
    NSLog(JSON);
} failure:nil];

[operation start];
Sign up to request clarification or add additional context in comments.

Comments

1

Add JSON Parser for Objective-c. Its opensource.

SBJSON *parser = [[SBJSON alloc] init];
NSString *tempStr = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];

// parse the JSON string into an object - assuming json_string is a NSString of JSON data
id object = [parser objectWithString:tempStr error:nil];

[resultObj release];
resultObj = [object retain];

Comments

-1
NSDictionary* myDict =  [NSJSONSerialization JSONObjectWithData:myJsonData 
                                                        options:0 
                                                          error:&error];

1 Comment

the OP asks how to retrieve the JSON, not how to parse it.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.