예제 #1
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
            MUJson.lastDecode = json;
            try
            {
                if (json != null)
                {
                    char[] charArray = json.ToCharArray();
                    int    index     = 0;
                    bool   success   = true;
                    object value     = MUJson.parseValue(charArray, ref index, ref success);

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

                    return(value);
                }
                else
                {
                    return(null);
                }
            }
            catch (Exception)
            {
                //DataHelper.WriteFormatExceptionLog(ex, string.Format("jsonDecode异常:{0}", json), false);
                return(null);
            }
        }
예제 #2
0
        public static object jsonDecode(string json)
        {
            MUJson.lastDecode = json;
            object result;

            try
            {
                if (json != null)
                {
                    char[] charArray = json.ToCharArray();
                    int    index     = 0;
                    bool   success   = true;
                    object value     = MUJson.parseValue(charArray, ref index, ref success);
                    if (success)
                    {
                        MUJson.lastErrorIndex = -1;
                    }
                    else
                    {
                        MUJson.lastErrorIndex = index;
                    }
                    result = value;
                }
                else
                {
                    result = null;
                }
            }
            catch (Exception)
            {
                result = null;
            }
            return(result);
        }
예제 #3
0
        protected static Hashtable parseObject(char[] json, ref int index)
        {
            Hashtable table = new Hashtable();

            MUJson.nextToken(json, ref index);
            bool done = false;

            while (!done)
            {
                int token = MUJson.lookAhead(json, index);
                if (token != 0)
                {
                    if (token == 6)
                    {
                        MUJson.nextToken(json, ref index);
                    }
                    else
                    {
                        if (token == 2)
                        {
                            MUJson.nextToken(json, ref index);
                            return(table);
                        }
                        string name = MUJson.parseString(json, ref index);
                        if (name == null)
                        {
                            return(null);
                        }
                        token = MUJson.nextToken(json, ref index);
                        if (token != 5)
                        {
                            return(null);
                        }
                        bool   success = true;
                        object value   = MUJson.parseValue(json, ref index, ref success);
                        if (!success)
                        {
                            return(null);
                        }
                        table[name] = value;
                    }
                    continue;
                }
                return(null);
            }
            return(table);
        }
예제 #4
0
        protected static ArrayList parseArray(char[] json, ref int index)
        {
            ArrayList array = new ArrayList();

            MUJson.nextToken(json, ref index);
            bool done = false;

            while (!done)
            {
                int token = MUJson.lookAhead(json, index);
                if (token != 0)
                {
                    if (token == 6)
                    {
                        MUJson.nextToken(json, ref index);
                    }
                    else
                    {
                        if (token == 4)
                        {
                            MUJson.nextToken(json, ref index);
                            break;
                        }
                        bool   success = true;
                        object value   = MUJson.parseValue(json, ref index, ref success);
                        if (!success)
                        {
                            return(null);
                        }
                        array.Add(value);
                    }
                    continue;
                }
                return(null);
            }
            return(array);
        }