1

i m parsing a json url using SBJSON and everything works fine. the problem is if m to parse the tag "title" or bascially any other tag and store it in an array named story.. i m able to get only the last value containing the tag and not the entire list of values stored in the array named story below is the code..

- (void)viewDidLoad {
[super viewDidLoad];
jsonurl=[NSURL URLWithString:@"http://www.1040communications.net/sheeba/stepheni/iphone/stephen.json"];
jsonData=[[NSString alloc]initWithContentsOfURL:jsonurl];
jsonArray = [jsonData JSONValue]; 

items = [jsonArray objectForKey:@"items"];
for (NSDictionary *item in items )
{
    story = [NSMutableArray array];
    description1 = [NSMutableArray array];

    [story addObject:[item objectForKey:@"title"]];
    [description1 addObject:[item objectForKey:@"description"]];


}
 NSLog(@"booom:%@",story);}
1
  • gime me ur output log of json Commented Aug 2, 2011 at 11:51

2 Answers 2

1

The story and description1 should be declared before the loop starts.

Sign up to request clarification or add additional context in comments.

Comments

1

This line should be outside the for loop

 story = [NSMutableArray array];

The NSMutableArray is being created for every item in your dictionary and hence you are getting the last value only. So you need to create the dictionary before you enter the for loop.

Comments

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.