i have this json string
{
\"@uri\": \"http://localhost:8080/TunisairRESTful/resources/cities/\",
\"city\": [
{
\"@uri\": \"http:/
Michael is right. Here's a more detailed answer:
initWithContentsOfFile
takes a string containing a file path (e.g. "/users/mehdi/documents/myFile.txt"). You seem to be passing in your actual JSON string, which isn't a file path. As a result, initWithContentsOfFile
is probably returning nil
.
Check this by asking:
if (myJSON == nil) NSLog(@"myJSON variable == nil!");
If it is nil, then your code is also setting json
and citysList
to nil.
Try this:
NSDictionary *json = [responseString JSONValue];
NSArray *citysList = [json objectForKey:@"city"];
NSLog(@" number of element : %d", [citysList count]);
You're doing an initWithContentsOfFile but passing in a string. Have you tried simply [responseString JSONValue]? Your code suggests that responseString has the PATH to the file you're trying to open, not your full response string itself.