Reputation: 497
I'm using Three20 and want to use JSON to populate my TTPhotoViewController
.
If I go to a web address, let's say,
www.bbc.com/jsonoutput
I get the following
{"name":"MyName","curNiceDate":"Wed 29 Dec 10","images":["UK\/2010\/12\/29\/1.jpg","US\/2010\/12\/29\/2.jpg","EU``\/2010\/12\/29\/3.jpg","FR\/2010\/12\/29\/4.jpg","FR\/2010\/12\/29\/5.jpg","FR\/2010\/12\/29\/6.jpg","FR\/2010\/12\/29\/7.jpg","FR\/2010\/12\/29\/8.jpg","FR\/2010\/12\/29\/9.jpg"]}
I want to pick out images which are in www.bbc.com/images/
.
All those directories are locations of images relevant from the above address. How would I go about pulling out this information from the JSON output and make it into a URL which will look like this
www.bbc.com/UK/2010/12/29/1.jpg
www.bbc.com/US/2010/12/29/2.jpg
www.bbc.com/EU/2010/12/29/3.jpg
www.bbc.com/FR/2010/12/29/4.jpg
So I can feed it into the TTPhotoView Picker.
Any help please?
Upvotes: 0
Views: 1534
Reputation: 11315
I've been happy with TouchJSON, it's also very easy to use. I'm using it in conjunction with ASIHTTPRequest.
Here's a quick modification of my code to relate to your question.
- (IBAction)getImages{
NSURL *url = [NSURL URLWithString:@"www.bbc.com/jsonoutput"];
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
[request setDelegate:self];
[request startAsynchronous];
}
- (void)requestFinished:(ASIHTTPRequest *)request{
NSError *error;
NSDictionary *bbcData = [[CJSONDeserializer deserializer] deserializeAsDictionary:[request responseData] error:&error];
//TODO: do something with the error
NSArray *images = [bbcData objectAtIndex:@"images"];
NSLog(@"%@", images);
}
- (void)requestFailed:(ASIHTTPRequest *)request{
NSError *error = [request error];
//TODO: do something with the error
}
Upvotes: 3
Reputation: 13773
https://github.com/stig/json-framework It's super easy to use. If you get stuck just look at how I used it in my code here
Upvotes: 1