Suggestion for error messages

Nov 3, 2008 at 5:17 PM
Hello again, I have a quick suggestion.  This is based off an older version of code, so it might be taken into account now, but here's the suggestion anyway:

When you return error messages from JSON.Net - specifically during the parsing of the JSON string during deserialization, it would be useful if the error messages returned more than the _currentchar.  Getting back an error message like "After parsing a value an unexpected character was encoutered: p" isn't very helpful, since I might have a LOT of "p" characters in my badly formatted string. :)

What I did in my copy of the code was to bring back your _testbuffer variable that you had commented out, made it available to the JsonTextReader and then made sure it was always getting added to with the MoveNext().  Then, if an error occurs, I have the error go get the last 30 characters of the _testbuffer and report that back instead.  (I made a common function to do this and also strip out any formatting characters like \n \r and \t).  This makes an error message that is far more useful:

"After parsing a value an unexpected character was encoutered: some text here}xtype:'p"

Which gives you a lot more to go on when trying to track down some little character that's messed up.

I'm in the middle of hacking together a quick and dirty JSON checker and reformatter, based off of your code and some parsing / formatting code of my own.  If there is any better way to get errors about formatting / JSON syntax checking, let me know.  Right now I'm just doing some custom formatting of the string then trying to deserialize it.