Ejemplo n.º 1
0
    /// <summary>
    /// 保存json文件到本地
    /// </summary>
    /// <param name="path">文件路径</param>
    /// <param name="jsonData">json数据</param>
    /// <returns></returns>
    public bool SaveJsonToLocal(string path, Hashtable jsonData)
    {
        string s      = TinyJSON.jsonEncode(jsonData);
        bool   result = SaveJsonToLocal(path, s);

        return(result);
    }
Ejemplo n.º 2
0
    /// <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 = TinyJSON.serializeValue(json, builder);

        return(success ? builder.ToString() : null);
    }
Ejemplo n.º 3
0
    /// <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
        TinyJSON.lastDecode = json;

        if (json != null)
        {
            char[] charArray = json.ToCharArray();
            int    index     = 0;
            bool   success   = true;
            object value     = TinyJSON.parseValue(charArray, ref index, ref success);

            if (success)
            {
                TinyJSON.lastErrorIndex = -1;
            }
            else
            {
                TinyJSON.lastErrorIndex = index;
            }

            return(value);
        }
        else
        {
            return(null);
        }
    }
Ejemplo n.º 4
0
        public void AddMessage(string jsonStr,byte[] data)
        {
            if (jsonStr.StartsWith("{") && jsonStr.EndsWith("}"))
            {
                Hashtable table = new Hashtable();

                table = TinyJSON.jsonDecode(jsonStr) as Hashtable;

                Message myMessage = new Message();
                myMessage.hashtable = table;
                myMessage.data = data;
                m_MyMessageControl.AddMessage(myMessage);
            }
        }
Ejemplo n.º 5
0
    private IEnumerator LoadJsonCoroutine(string url, Action <Hashtable> callback)
    {
        WWW www = new WWW(url);

        yield return(www);

        if (www.error != null)
        {
            Debug.Log("加载JSON失败:" + www.error);
        }
        else
        {
            try
            {
                Hashtable data = TinyJSON.jsonDecode(www.text) as Hashtable;
                callback(data);
            }
            catch
            {
                Debug.Log("JSON格式错误");
            }
        }
        www.Dispose();
    }
Ejemplo n.º 6
0
 public static Hashtable hashtableFromJson(this string json)
 {
     return(TinyJSON.jsonDecode(json) as Hashtable);
 }
Ejemplo n.º 7
0
 public static ArrayList arrayListFromJson(this string json)
 {
     return(TinyJSON.jsonDecode(json) as ArrayList);
 }
Ejemplo n.º 8
0
 public static string toJson(this Dictionary <string, string> obj)
 {
     return(TinyJSON.jsonEncode(obj));
 }
Ejemplo n.º 9
0
 public static string toJson(this Hashtable obj)
 {
     return(TinyJSON.jsonEncode(obj));
 }