TinyJSON Files

5 views
Skip to first unread message

Devin

unread,
Feb 12, 2009, 11:55:16 AM2/12/09
to Mizzou Game Design
From TinyJSON's webpage, the way to parse a file is like this:

json::grammar<char>::variant v = json::parse(strInput.begin(),
strInput.end());

if(v->type() != typeid(json::grammar<char>::object))
{
// ERROR: parsing failed (bad format)
return false;
}


This is how I am doing it in the JSONFile class. For test_level.json,
parsing it reaches inside the if statement, meaning there was some
error.

When testing JSONFile, I had this problem even though the JSON file
was apparently correct. I used an editor called "gedit" when making
this test JSON file. I randomly decided to try a different editor,
emacs, to make the JSON file, and then json::parse() succeeded.

In conclusion, I think some editors are adding special characters into
the file that cause json::parse() to fail. I remember Chad saying he
had used TinyJSON before; have you had any similar experiences?

Devin

unread,
Feb 12, 2009, 12:24:01 PM2/12/09
to Mizzou Game Design
Actually, upon further investigation, it appears a new line at the end
of the file causes the error.

Devin

unread,
Feb 12, 2009, 3:17:17 PM2/12/09
to Mizzou Game Design
Upon more further investigation, my previous post is correct, but I
have discovered a problem with test_level.json. You cannot have an
array of variables ("name" : "value").

Chad

unread,
Feb 13, 2009, 10:20:17 AM2/13/09
to Mizzou Game Design
Ah yeah, that's right. I hadn't gotten around to playing with the
file yet just
mocked it up. I'll change it to use arrays of objects. That's about
the only
gripe I have with tinyJSON, that it doesn't really produce meaningful
errors.
But of course it's a small library meant for production use so it
wouldn't
give proper errors. Thanks!
Reply all
Reply to author
Forward
0 new messages