Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I am currently working on an iPhone application that takes in data from the following source:

I am trying to figure out how to parse it into a human readable format in say a text field.

My code so far is:

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];

    NSString *urlString = [NSString        stringWithFormat:@"http://dev.threesixtyapp.com/api/events.php?action=available&id=1"];

    NSURL *url =[NSURL URLWithString:urlString];

    NSData *data = [NSData dataWithContentsOfURL:url];

    NSError  *error;

    NSMutableDictionary *json = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&error];

    NSLog(@"%@",json);

}
share|improve this question

2 Answers

http://stig.github.com/json-framework/ - SBJson is a great framework for encoding/decoding JSON. I recommend you check it out...It will parse it for you into an NSDictionary, and you simply set the text of the textfield equal to the value in the NSDictionary that you want. It's pretty straightforward using this framework. Your Json should just be a string when you pass it to the SBJson functions btw

share|improve this answer
SBJson is good, but JSONKit is the best. – Cyrille Jul 9 '12 at 15:21
what's better about it? – sunrize920 Jul 9 '12 at 15:30
It's much faster. Even faster than Apple's native plist serialization/deserialization. Check out the speed comparisons on their project page! – Cyrille Jul 9 '12 at 15:37

First of all you have to understand the data structure of you json.
You can use JSON Viewer to view the data structure of your json.
As I can see you are getting array of objects consisting of event_title, date_from and date_to.

NSArray *jsonArry = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&error];
NSLog(@"%@",jsonArry);
for (NSDictionary *dict in jsonArry) {
    NSString * title = [dict objectForKey:@"event_title"];
    NSString * dateTo = [dict objectForKey:@"date_to"];
    NSString * dateFrom = [dict objectForKey:@"date_from"]; 
    NSLog(@"title=%@,dateTo=%@,dateFrom=%@",title,dateTo,dateFrom);
}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.