/* * [2012-06-09 First Version] * - provides strongly typed node classes and lists / dictionaries * - provides easy access to class members / array items / data values * - the parser now properly identifies types. So generating JSON with this framework should work. * - only double quotes (") are used for quoting strings. * - provides "casting" properties to easily convert to / from those types: * int / float / double / bool * - provides a common interface for each node so no explicit casting is required. * - the parser tries to avoid errors, but if malformed JSON is parsed the result is more or less undefined * - It can serialize/deserialize a node tree into/from an experimental compact binary format. It might * be handy if you want to store things in a file and don't want it to be easily modifiable * * [2012-12-17 Update] * - Added internal JSONLazyCreator class which simplifies the construction of a JSON tree * Now you can simple reference any item that doesn't exist yet and it will return a JSONLazyCreator * The class determines the required type by it's further use, creates the type and removes itself. * - Added binary serialization / deserialization. * - Added support for BZip2 zipped binary format. Requires the SharpZipLib ( http://www.icsharpcode.net/opensource/sharpziplib/ ) * The usage of the SharpZipLib library can be disabled by removing or commenting out the USE_SharpZipLib define at the top * - The serializer uses different types when it comes to store the values. Since my data values * are all of type string, the serializer will "try" which format fits best. The order is: int, float, double, bool, string. * It's not the most efficient way but for a moderate amount of data it should work on all platforms. * * [2017-03-08 Update] * - Optimised parsing by using a StringBuilder for token. This prevents performance issues when large * string data fields are contained in the json data. * - Finally refactored the badly named JSONClass into JSONObject. * - Replaced the old JSONData class by distict typed classes ( JSONString, JSONNumber, JSONBool, JSONNull ) this * allows to propertly convert the node tree back to json without type information loss. The actual value * parsing now happens at parsing time and not when you actually access one of the casting properties. * * [2017-04-11 Update] * - Fixed parsing bug where empty string values have been ignored. * - Optimised "ToString" by using a StringBuilder internally. This should heavily improve performance for large files * - Changed the overload of "ToString(string aIndent)" to "ToString(int aIndent)" * * [2017-11-29 Update] * - Removed the IEnumerator implementations on JSONArray & JSONObject and replaced it with a common * struct Enumerator in JSONNode that should avoid garbage generation. The enumerator always works * on KeyValuePair, even for JSONArray. * - Added two wrapper Enumerators that allows for easy key or value enumeration. A JSONNode now has * a "Keys" and a "Values" enumerable property. Those are also struct enumerators / enumerables * - A KeyValuePair can now be implicitly converted into a JSONNode. This allows * a foreach loop over a JSONNode to directly access the values only. Since KeyValuePair as well as * all the Enumerators are structs, no garbage is allocated. * - To add Linq support another "LinqEnumerator" is available through the "Linq" property. This * enumerator does implement the generic IEnumerable interface so most Linq extensions can be used * on this enumerable object. This one does allocate memory as it's a wrapper class. * - The Escape method now escapes all control characters (# < 32) in strings as uncode characters * (\uXXXX) and if the static bool JSONNode.forceASCII is set to true it will also escape all * characters # > 127. This might be useful if you require an ASCII output. Though keep in mind * when your strings contain many non-ascii characters the strings become much longer (x6) and are * no longer human readable. * - The node types JSONObject and JSONArray now have an "Inline" boolean switch which will default to * false. It can be used to serialize this element inline even you serialize with an indented format * This is useful for arrays containing numbers so it doesn't place every number on a new line * - Extracted the binary serialization code into a seperate extension file. All classes are now declared * as "partial" so an extension file can even add a new virtual or abstract method / interface to * JSONNode and override it in the concrete type classes. It's of course a hacky approach which is * generally not recommended, but i wanted to keep everything tightly packed. * - Added a static CreateOrGet method to the JSONNull class. Since this class is immutable it could * be reused without major problems. If you have a lot null fields in your data it will help reduce * the memory / garbage overhead. I also added a static setting (reuseSameInstance) to JSONNull * (default is true) which will change the behaviour of "CreateOrGet". If you set this to false * CreateOrGet will not reuse the cached instance but instead create a new JSONNull instance each time. * I made the JSONNull constructor private so if you need to create an instance manually use * JSONNull.CreateOrGet() * * [2018-01-09 Update] * - Changed all double.TryParse and double.ToString uses to use the invariant culture to avoid problems * on systems with a culture that uses a comma as decimal point. * * [2018-01-26 Update] * - Added AsLong. Note that a JSONNumber is stored as double and can't represent all long values. However * storing it as string would work. * - Added static setting "JSONNode.longAsString" which controls the default type that is used by the * LazyCreator when using AsLong * * [2018-04-25 Update] * - Added support for parsing single values (JSONBool, JSONString, JSONNumber, JSONNull) as top level value. * * [2019-02-18 Update] * - Added HasKey(key) and GetValueOrDefault(key, default) to the JSONNode class to provide way to read * values conditionally without creating a LazyCreator * * [2019-03-25 Update] * - Added static setting "allowLineComments" to the JSONNode class which is true by default. This allows * "//" line comments when parsing json text as long as it's not within quoted text. All text after // up * to the end of the line is completely ignored / skipped. This makes it easier to create human readable * and editable files. Note that stripped comments are not read, processed or preserved in any way. So * this feature is only relevant for human created files. * - Explicitly strip BOM (Byte Order Mark) when parsing to avoid getting it leaked into a single primitive * value. That's a rare case but better safe than sorry. * - Allowing adding the empty string as key * * [2019-12-10 Update] * - Added Clone() method to JSONNode to allow cloning of a whole node tree. * * [2020-09-19 Update] * - Added Clear() method to JSONNode. * - The parser will now automatically mark arrays or objects as inline when it doesn't contain any * new line characters. This should more or less preserve the layout. * - Added new extension file "SimpleJSONDotNetTypes.cs" to provide support for some basic .NET types * like decimal, char, byte, sbyte, short, ushort, uint, DateTime, TimeSpan and Guid as well as some * nullable types. * - Fixed an error in the Unity extension file. The Color component order was wrong (it was argb, now it's rgba) * - There are now two static float variables (ColorDefaultAlpha and Color32DefaultAlpha) to specify the default * alpha values when reading UnityEngine.Color / Color32 values where the alpha value is absent. The default * values are 1.0f and 255 respectively. */