Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS

Alex Hedley
Alex Hedley
16,381 Points

JSON is null

Hi Guys,

Just trying to adapt the Blog Reader for my own use.

I've got a Films blog I started a few years back. I've recently created a JSON file so I can use in an app.

http://www.alexhedley.com/films/json/

I've checked on http://jsonlint.com/ and it returns VALID.

If I log the Data it returns something.

NSLog(@"DATA: %@",jsonData);
DATA: <7b202274 69746c65 22203a20 22416c65 78204865 646c6579 etc

But

NSDictionary *dataDictionary = [NSJSONSerialization JSONObjectWithData:jsonData options:0 error:&error];
NSLog(@"DICT: %@",dataDictionary);
DICT: (null)

I ran a check also and that is returning False:

BOOL isTurnableToJSON = [NSJSONSerialization isValidJSONObject: jsonData];
NSLog(@"isTurnableToJSON: %d", isTurnableToJSON);
isTurnableToJSON: 0
Amit Bijlani
Amit Bijlani
Treehouse Guest Teacher

Output the error variable and see if it has any info: NSLog(@"%@",error);

Alex Hedley
Alex Hedley
16,381 Points

Thanks, should have thought of that,

2013-06-27 23:33:49.788 BlogReader[519:c07]
Error Domain=NSCocoaErrorDomain Code=3840
"The operation couldn’t be completed. (Cocoa error 3840.)"
(Unable to convert data to string around character 563.)
UserInfo=0x8540090
{NSDebugDescription=Unable to convert data to string around character 563.}

If I change the URL to http://www.alexhedley.com/films/json/?id=1

2013-06-27 23:35:26.726 BlogReader[555:c07]
Error Domain=NSCocoaErrorDomain Code=3840
"The operation couldn’t be completed. (Cocoa error 3840.)"
(Unable to convert data to string around character 562.) UserInfo=0x769f300
{NSDebugDescription=Unable to convert data to string around character 562.}

I'll do some more digging...

Alex Hedley
Alex Hedley
16,381 Points

So it looks like it was the Rating that was the issue,

Removed the following from the file

rating: "****°",

"rating" : "****°" ,
          /|\

and it's looking a little more healthy.

Changed this to just a number anyway so didn't really need this anymore it was just the original way I used to score them.

2 Answers

Amit Bijlani
STAFF
Amit Bijlani
Treehouse Guest Teacher

Great! so I'm assuming you resolved the issue

Amit Bijlani
Amit Bijlani
Treehouse Guest Teacher

Looks good! Let me know when you launch if you launch it to the app store!