0

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?

Pang
  • 9,564
  • 146
  • 81
  • 122
user370507
  • 477
  • 2
  • 12
  • 20
  • See [this question](http://stackoverflow.com/questions/2256625/comparison-of-json-parser-for-objective-c-json-framework-yajl-touchjson-etc) for information on the various JSON libraries. I happen to be the author of [JSONKit](https://github.com/johnezang/JSONKit). – johne Dec 30 '10 at 06:04

3 Answers3

3

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
}
keegan3d
  • 10,357
  • 9
  • 53
  • 77
  • Thanks for the example! It really helped as i have a better idea now! I was told that Three20 has its own JSON Parser, trying to use that parser instead of importing another one, but struggling – user370507 Dec 30 '10 at 10:45
  • Ah cool, good to know. I have't used the Three20 framework yet. – keegan3d Dec 31 '10 at 02:04
1

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

Matt S.
  • 13,305
  • 15
  • 73
  • 129
  • Thanks, I was told Three20 has its own JSON Parser, or is it better to import another one? – user370507 Dec 30 '10 at 10:44
  • 1
    https://github.com/facebook/three20/tree/master/src/extThree20JSON . Trying to use this to do the above – user370507 Dec 30 '10 at 11:09
  • 1
    It uses the same framework to do it... https://github.com/facebook/three20/tree/master/src/extThree20JSON/Vendors/JSON – Matt S. Dec 31 '10 at 22:44
0

json-framework is good use it.

rain
  • 1
  • 2