/// <summary> /// Converts a Hashtable / ArrayList / Dictionary(string,string) object into a JSON string /// </summary> /// <param name="json">A Hashtable / ArrayList</param> /// <returns>A JSON encoded string, or null if object 'json' is not serializable</returns> public static string jsonEncode(object json) { var builder = new StringBuilder(BUILDER_CAPACITY); var success = UIJson.serializeValue(json, builder); return(success ? builder.ToString() : null); }
/// <summary> /// Parses the string json into a value /// </summary> /// <param name="json">A JSON string.</param> /// <returns>An ArrayList, a Hashtable, a double, a string, null, true, or false</returns> public static object jsonDecode(string json) { // save the string for debug information UIJson.lastDecode = json; if (json != null) { char[] charArray = json.ToCharArray(); int index = 0; bool success = true; object value = UIJson.parseValue(charArray, ref index, ref success); if (success) { UIJson.lastErrorIndex = -1; } else { UIJson.lastErrorIndex = index; } return(value); } else { return(null); } }
void ParseJson() // 解析json { TextAsset Json = Resources.Load <TextAsset>("UIInfo"); UIJson JsonObject = JsonUtility.FromJson <UIJson>(Json.text); foreach (UIModel Model in JsonObject.ModelList) { // Debug.Log(Model.Type + " " + Model.Path); PathDict.Add(Model.Type, Model.Path); } }