Пример #1
0
        ////////////////////////////////////////////////////////////////////////////
        //--------------------------------- REVISIONS ------------------------------
        // Date       Name                 Tracking #         Description
        // ---------  -------------------  -------------      ----------------------
        // 07JUN2009  James Shen                 	          Initial Creation
        ////////////////////////////////////////////////////////////////////////////
        /**
         * Construct a JSONObject from a JSONTokener.
         * @param x A JSONTokener object containing the source string.
         * @throws JSONException If there is a syntax error in the source string.
         */
        internal JSONObject(JSONTokener x)
            : this()
        {
            if (x.NextClean() != '{')
            {
                throw x.SyntaxError("A JSONObject text must begin with '{'");
            }
            for (; ; )
            {
                var c = x.NextClean();
                string key;
                switch (c)
                {
                    case '\0':
                        throw x.SyntaxError("A JSONObject text must end with '}'");
                    case '}':
                        return;
                    default:
                        x.Back();
                        key = x.NextValue().ToString();
                        break;
                }

                /*
                 * The key is followed by ':'. We will also tolerate '=' or '=>'.
                 */

                c = x.NextClean();
                if (c == '=')
                {
                    if (x.Next() != '>')
                    {
                        x.Back();
                    }
                }
                else if (c != ':')
                {
                    throw x.SyntaxError("Expected a ':' after a key");
                }
                Put(key, x.NextValue());

                /*
                 * Pairs are separated by ','. We will also tolerate ';'.
                 */

                switch (x.NextClean())
                {
                    case ';':
                    case ',':
                        if (x.NextClean() == '}')
                        {
                            return;
                        }
                        x.Back();
                        break;
                    case '}':
                        return;
                    default:
                        throw x.SyntaxError("Expected a ',' or '}'");
                }
            }
        }
Пример #2
0
 ////////////////////////////////////////////////////////////////////////////
 //--------------------------------- REVISIONS ------------------------------
 // Date       Name                 Tracking #         Description
 // ---------  -------------------  -------------      ----------------------
 // 07JUN2009  James Shen                 	          Initial Creation
 ////////////////////////////////////////////////////////////////////////////
 /**
  * Construct a JSONArray from a JSONTokener.
  * @param x A JSONTokener
  * @ If there is a syntax error.
  */
 internal JSONArray(JSONTokener x)
     : this()
 {
     if (x.NextClean() != '[')
     {
         throw x.SyntaxError("A JSONArray text must start with '['");
     }
     if (x.NextClean() == ']')
     {
         return;
     }
     x.Back();
     for (; ; )
     {
         if (x.NextClean() == ',')
         {
             x.Back();
             _myArrayList.Add(null);
         }
         else
         {
             x.Back();
             _myArrayList.Add(x.NextValue());
         }
         switch (x.NextClean())
         {
             case ';':
             case ',':
                 if (x.NextClean() == ']')
                 {
                     return;
                 }
                 x.Back();
                 break;
             case ']':
                 return;
             default:
                 throw x.SyntaxError("Expected a ',' or ']'");
         }
     }
 }