Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error when using Brautaset Json framework in iphone

Tags:

json

http

iphone

I'm trying to make a http request. The code looks like this:

NSString *urlString = [NSString stringWithString:@"http://www.foo.se/bartojson.php?venue=47497"]; 


NSLog(@"retain %d urlString %@", [urlString retainCount], urlString );
    NSURL *url = [NSURL URLWithString:urlString];
    [urlString release];

    NSString *jsonString = [NSString stringWithContentsOfURL:url];
    NSDictionary *httpResult = [jsonString JSONValue];

When calling the page in a browser the result looks like this:

{"name": "test" ,"description": "This is a test." ,"reviews": [{"grade": "5", "description": "Nice"},{"grade": "3", "description": "Very nice!"}]}

But when calling it from the code i get this:

Error Domain=org.brautaset.JSON.ErrorDomain Code=3 UserInfo=0x582640 "Object value expected for key: reviews"

There seems to be some problem with the reviews pointing to a new dictionary. Could you please help me understand this error message.

like image 488
jakob Avatar asked May 30 '09 11:05

jakob


2 Answers

Well I found the reason for my error. Stupid windows linebreaks within the result made the JSONValue call fail. Removed all \r and viola everything works like a charm!

like image 106
jakob Avatar answered Sep 29 '22 10:09

jakob


Dunno if it was a typo, but your example is not valid JSON, because of the comma following "Nice". JSON does not allow trailing commas in arrays or dictionaries ("Objects"). JSON.framework would certainly kick up a fuzz about that.

By the way, if you're using the current stable version of the framework it will always print the full stack of the failure to the Console log, if you're using the convenience methods. Otherwise, you can ask the parser object for a full stack trace and print it yourself.

like image 35
Stig Brautaset Avatar answered Sep 29 '22 10:09

Stig Brautaset