1.Assets下创建文件夹Plugins
2.在Plugins下创建脚本SimpleJSON
3.将下面内容复制进脚/* * * * *
* A simple JSON Parser / builder
* ------------------------------
*
* It mainly has been written as a simple JSON parser. It can build a JSON string
* from the node-tree, or generate a node tree from any valid JSON string.
*
* If you want to use compression when saving to file / stream / B64 you have to include
* SharpZipLib ( http://www.icsharpcode.net/opensource/sharpziplib/ ) in your project and
* define "USE_SharpZipLib" at the top of the file
*
* Written by Bunny83
* 2012-06-09
*
* [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<string, JSONNode>, 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<string, JSONNode> 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()
*
*
* The MIT License (MIT)
*
* Copyright (c) 2012-2017 Markus Göbel (Bunny83)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* * * * */
using System;
using System.Collections; using System.Collections.Generic; using System.Linq; using System.Text; namespace SimpleJSON { public enum JSONNodeType { Array = 1, Object = 2, String = 3, Number = 4, NullValue = 5, Boolean = 6, None = 7, Custom = 0xFF, } public enum JSONTextMode { Compact, Indent } public abstract partial class JSONNode { #region Enumerators public struct Enumerator { private enum Type { None, Array, Object } private Type type; private Dictionary<string, JSONNode>.Enumerator m_Object; private List<JSONNode>.Enumerator m_Array; public bool IsValid { get { return type != Type.None; } } public Enumerator(List<JSONNode>.Enumerator aArrayEnum) { type = Type.Array; m_Object = default(Dictionary<string, JSONNode>.Enumerator); m_Array = aArrayEnum; } public Enumerator(Dictionary<string, JSONNode>.Enumerator aDictEnum) { type = Type.Object; m_Object = aDictEnum; m_Array = default(List<JSONNode>.Enumerator); } public KeyValuePair<string, JSONNode> Current { get { if (type == Type.Array) return new KeyValuePair<string, JSONNode>(string.Empty, m_Array.Current); else if (type == Type.Object) return m_Object.Current; return new KeyValuePair<string, JSONNode>(string.Empty, null); } } public bool MoveNext() { if (type == Type.Array) return m_Array.MoveNext(); else if (type == Type.Object) return m_Object.MoveNext(); return false; } } public struct ValueEnumerator { private Enumerator m_Enumerator; public ValueEnumerator(List<JSONNode>.Enumerator aArrayEnum) : this(new Enumerator(aArrayEnum)) { } public ValueEnumerator(Dictionary<string, JSONNode>.Enumerator aDictEnum) : this(new Enumerator(aDictEnum)) { }