0
NSString *responseString = [request responseString];
NSDictionary *dictionary=[responseString JSONValue];
NSArray *dic=[dictionary valueForKey:@"data"];

 for (int a=0; a<dic.count; a++) {
        NSInteger z=(NSInteger)a;
        NSLog(@"%@",[[dic objectAtIndex:a] objectForKey:@"nom"]);
    }

this is the file

{"data":[ "",{"id":"1","nom":"hello","message":["",{"id":1,"nom":"dad"}]}, {"id":"2","nom":"hi","message":["",{"id":"1","nom":"marie"},{"id":"2","nom":"bob‌​"}]} ] }

When I want to parcour my json file, I saw the problem whith variable "a" in objectAtIndex because it's an integer, but if I try value 5 for exemple it's work's perfect.

Can you help me please.

10
  • Please share the log of dictionary Commented Mar 8, 2013 at 15:13
  • yes im using #import "ASIHTTPRequest.h" #import "SBJson.h" Commented Mar 8, 2013 at 15:17
  • I think Anupdas meant you should share the actual JSON data :) Commented Mar 8, 2013 at 15:20
  • 4
    What do you mean by problem? Does it crash? Throw an exception? Provide unexpected data? Commented Mar 8, 2013 at 15:23
  • 1
    Well, as you see your first object is just an empty string ("") and that is the problem (you try to get a value like it was a dictionary) Commented Mar 8, 2013 at 15:31

1 Answer 1

1

Take a look at your data array... The very first object is an empty string. So, you're trying to send an objectForKey: message to it (believing that is a dictionary) and you get a crash. You should either remove your object or implement a logic that would try to inspect each object before trying to pull a value.

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

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.