views:

43

answers:

1

I am trying to parse the JSON returned here: http://www.waterwayguide.com/map/php/bridge.php?ll=25.514339,-80.076164

However, I can't parse it as I normally would it seems:

NSData *jsonData = [[(ASIHTTPRequest*)[data objectForKey:@"request"] responseString] dataUsingEncoding:NSUTF32BigEndianStringEncoding]; 
NSLog(@"this prints as expected %@", [(ASIHTTPRequest*)[data objectForKey:@"request"] responseString]);
NSArray* jsonNodes = [[CJSONDeserializer deserializer] deserialize:jsonData error:&error];
NSLog(@"this is unexpectedly nil %@", jsonNodes);

I have used this precise code on a different JSON feed and it works nicely. Is there something I can do on the client side to parse this feed properlY?

+2  A: 

That feed isn't JSON. Look at the source. It's text/html and it doesn't validate because it attempts to escape ' with \'. Altogether, it seems to be a quick attempt to manually output JSON instead of HTML.

Matthew Flaschen
Those br-tags appear to be in the middle of a string literal, so it's allowed.
roe
@roe, yes, that's one of the symptoms, not the reason it's invalid.
Matthew Flaschen
I ran it through jsfiddle, and it seems quite valid. http://jsfiddle.net/SNTgf/
roe
@roe, it's not. Use [JSONLint](http://www.jsonlint.com/) or check [the RFC](http://www.ietf.org/rfc/rfc4627.txt). \' is not an allowed escape. JSON is a *subset* of JavaScript object literal syntax (what you're using in that script).
Matthew Flaschen
Cool, thanks for the link. You're right. json.org has a graphic representation of the allowed characters too.
roe
@Matthew Flaschen: +1 for the link to JSONLint. That looks a very useful tool.
JeremyP