Wednesday, August 4, 2010

Trouble with JSON parsing in iPhone App

Programmer Question

I've been trying to make this work for some time now, but I think I need someone on the outside to see what I'm doing wrong. In my app, I'm getting a JSON value from a web server, and parsing it into my table view.



responseData = [NSData dataWithContentsOfURL: [NSURL URLWithString: @"http://myserver/json"]];
NSString *responseString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
NSDictionary *dict = [responseString JSONValue];
theData = [dict objectForKey:@"data"];


My only problem now, is that 'theData' is apparently a NSString, as far as I am able to see. The following error is what I get from GDB when I call '[theData count]' from my view controller.



-[NSCFString count]: unrecognized selector sent to instance 0x6eb5380


And what my JSON looks like



{
"code": 100,
"data": [
{
/** Some object */
}]
}


Find the answer here

No comments:

Post a Comment

LinkWithin

Related Posts with Thumbnails