For my project I have built my own api using PHP. The result of json encoding basically gives me an array of entries like below
{"terms":[
{"term0":
{"content":"test id",
"userid":"100","translateto":null,
"hastranslation":"0",
"created":"2011-10-19 16:54:57",
"updated":"2011-10-19 16:55:58"}
},
{"term1":
{"content":"Initial content",
"userid":"3","translateto":null,
"hastranslation":"0",
"created":"2011-10-19 16:51:33",
"updated":"2011-10-19 16:51:33"
}
}
]
}
However, I've been having problems working with NSMutableDictionary and extracting "content" in Objective-C.
- (void) connectionDidFinishLoading:(NSURLConnection *)connection {
[connection release];
NSString *responseString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
[responseData release];
NSMutableDictionary *JSONval = [responseString JSONValue];
[responseString release];
if (JSONval != nil) {
NSMutableDictionary *responseDataDict = [JSONval objectForKey:@"terms"];
if (responseDataDict!= nil) {
for (id key in responseDataDict) {
NSString *content = [[responseDataDict objectForKey:key]objectForKey:@"content"];
[terms addObject:content];
textView.text = [textView.text stringByAppendingFormat:@"\n%@", content];
}
button.enabled = YES;
}
}
}
Where NSLog spits out error when I send objectForKey to responseDataDict, which is a __NSArrayM according to the log.
What did I do wrong here?