Advertise here




Advertise here

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Parsing JSON into Fundamental STOCK

zachynekzachynek Posts: 39Registered Users
edited April 2011 in iOS SDK Development
As I have followed this tutorial http://www.iphonedevsdk.com/forum/iphone-sdk-tutorials/76730-webservice-how.html#post326403 I made my JSON file look like this:

[PHP]{"id":"1","name":"Programming","teacher":"Anders"}{"id":"7","name":"Test","teacher":"Tine"}[/PHP]

That means, I have 2 objects (two dictionaries to parse into Cocoa elements). Therefore, I save JSON value into an NSArray and then go through this array and getting value for each those two dictionaries:

[PHP] NSString *responseString = [[NSString alloc] initWithData:dataWebService encoding:NSUTF8StringEncoding];
NSLog(@Response: %@",responseString);

NSArray *arrayOfDictionaries = [responseString JSONValue];
for (int a=0; a<[arrayOfDictionaries count]; a++) {
NSDictionary *dictionary = [arrayOfDictionaries objectAtIndex:a];
NSString *name = (NSString*) [dictionary objectForKey:@name];
NSLog(@%@", name);
}[/PHP]

However I keep getting this error -JSONValue failed. Error trace is: (
"Error Domain=org.brautaset.JSON.ErrorDomain Code=10 \"Garbage after JSON\" UserInfo=0x4b50d30 {NSLocalizedDescription=Garbage after JSON}"
)
. Can somebody see what is wrong???
Post edited by zachynek on

Replies

Sign In or Register to comment.