I can successfully parse the contents of a JSON file, using the JSON-Framework 3.0, but I’m not being able to extract all elements of the NSArray.
The app crashes at this line (shown below) link = [myJsonArray objectAtIndex:0]; giving me this message on the console: -[__NSCFDictionary objectAtIndex:]: unrecognized selector sent to instance 0x70ea20.
Here is my code:
NSError *error;
NSString *link;
NSArray *myJsonArray;
NSString *jsonString = [[NSString alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"myJSONfile" ofType:@"json"] encoding:NSUTF8StringEncoding error:&error];
SBJsonParser *parser = [[SBJsonParser alloc] init];
myJsonArray = [[parser objectWithString:jsonString error:&error] copy];
[parser release];
link = [myJsonArray objectAtIndex:0];
NSLog(@"json returns: %@", myJsonArray);
And here is my JSON file:
{
"Programs": [
{"link1": "http://www.myWebSite1.aspx",
"program name": "Live Show at 9",
"speaker": "Dr. Speaker 1"},
{"link2": "http://www.myWebSite2.aspx",
"name": "Dr. Speaker 2",
"speaker": "Live Show at 10"}
]
}
This is the Log Output:
JSON Output: {
Programs = (
{
link1: "http://www.myWebSite1.aspx",
program name: "Live Show at 9",
speaker: "Dr. Speaker 1"},
{link2: "http://www.myWebSite2.aspx",
program name: "Dr. Speaker 2",
speaker: "Live Show at 10"}
);
}
What Am I doing wrong? Thanks for your help!
To access the link1 value you should use: