Beispiel #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
            MiniJSON.lastDecode = json;

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

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

                return(value);
            }
            else
            {
                return(null);
            }
        }
Beispiel #2
0
        protected static Hashtable parseObject(char[] json, ref int index)
        {
            Hashtable hashtable = new Hashtable();

            MiniJSON.nextToken(json, ref index);
            bool flag = false;

            while (!flag)
            {
                int num = MiniJSON.lookAhead(json, index);
                if (num == 0)
                {
                    return(null);
                }
                if (num == 6)
                {
                    MiniJSON.nextToken(json, ref index);
                }
                else
                {
                    if (num == 2)
                    {
                        MiniJSON.nextToken(json, ref index);
                        return(hashtable);
                    }
                    string text = MiniJSON.parseString(json, ref index);
                    if (text == null)
                    {
                        return(null);
                    }
                    num = MiniJSON.nextToken(json, ref index);
                    if (num != 5)
                    {
                        return(null);
                    }
                    bool   flag2 = true;
                    object obj   = MiniJSON.parseValue(json, ref index, ref flag2);
                    if (!flag2)
                    {
                        return(null);
                    }
                    hashtable.set_Item(text, obj);
                }
            }
            return(hashtable);
        }
Beispiel #3
0
 public static object jsonDecode(string json)
 {
     MiniJSON.lastDecode = json;
     if (json != null)
     {
         char[] json2  = json.ToCharArray();
         int    num    = 0;
         bool   flag   = true;
         object result = MiniJSON.parseValue(json2, ref num, ref flag);
         if (flag)
         {
             MiniJSON.lastErrorIndex = -1;
         }
         else
         {
             MiniJSON.lastErrorIndex = num;
         }
         return(result);
     }
     return(null);
 }
Beispiel #4
0
        protected static ArrayList parseArray(char[] json, ref int index)
        {
            ArrayList arrayList = new ArrayList();

            MiniJSON.nextToken(json, ref index);
            bool flag = false;

            while (!flag)
            {
                int num = MiniJSON.lookAhead(json, index);
                if (num == 0)
                {
                    return(null);
                }
                if (num == 6)
                {
                    MiniJSON.nextToken(json, ref index);
                }
                else
                {
                    if (num == 4)
                    {
                        MiniJSON.nextToken(json, ref index);
                        break;
                    }
                    bool   flag2 = true;
                    object obj   = MiniJSON.parseValue(json, ref index, ref flag2);
                    if (!flag2)
                    {
                        return(null);
                    }
                    arrayList.Add(obj);
                }
            }
            return(arrayList);
        }