tags:

views:

1082

answers:

3

Hello experts!

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.

A: 

Yes Jakob, I also get the same kind of error. Where can I find the description of the error codes for the JSON framework? Help please. //Knug

+1  A: 

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!

jakob
+1  A: 

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.

Stig Brautaset
Hi Stig! Sorry about the typo. There was nothing wrong with the framework, it was the server that returned hidden windows linebreaks.
jakob