Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

iOS

Alex Hedley
Alex Hedley
16,377 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,377 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,377 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!