简体   繁体   中英

Error when using Brautaset Json framework in 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.

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!

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM