Bunny83 / SimpleJSON

A simple JSON parser in C#
MIT License
735 stars 294 forks source link

How to cope with plain values #15

Closed wvdvegt closed 6 years ago

wvdvegt commented 6 years ago

Hi

I've had some issues with json input that is either an object or array and plain values like 32 and 42.45

JSON.Parse() does not seem to return anything (it shows { }, an empty object) with the plain values. Is it not supported (it is legal JSON and is part of the JSON standard a.t.m.) or am i doing anything wrong.

Bunny83 commented 6 years ago

Uhm do you have an actual example json string? Objects always have to contain key-value pairs. By "plain values" you probably mean numbers? At the moment the parser does not support a single number, bool, or string value. So currently it expects either an object or array as top level object. However I will add support for plain values, though this should be a really exceptional case as you can only store a single value that way.

Bunny83 commented 6 years ago

Just added this to the parser. Now it should support everything you can find here:

https://www.json.org/

Though of course the JSON format doesn't specify a specific binary number representation, I'm using double values as most parsers do. A double can represent int32 values without errors but for anything larger you may want to follow the recommendation and store the number as string. The implicit long conversion should work with string values if you set JSONNode.longAsString = true .

wvdvegt commented 6 years ago

Thx a Lot! I know the limitations on parsing text and date formats like date/time and floating points.

david-pfx commented 6 years ago

Numbers represented as double can handle integers up to 53 bits without loss of precision, but fall down badly on decimal fractions. The round-trip limit is around 15 decimal digits, which is not enough for many purposes (US GDP could not represent cents correctly). String as default is the safest.