Beispiel #1
0
        private int ReadDictionary(string input, int index)
        {
            index++;
            Content = new Dictionary<string, PrimitiveJSONObject>();
            while (true)
            {
                string key;
                if (input[index] == '\"')
                {
                    PrimitiveJSONObject sub = new PrimitiveJSONObject();
                    index = sub.Read(input, index);
                    key = sub.Value;
                }
                else if (input[index] == '}')
                {
                    return ++index;
                }
                else
                {
                    throw new Exception("Bad JSON format.");
                }

                if (input[index] == ':')
                {
                    index++;
                }
                else
                {
                    throw new Exception("Bad JSON format.");
                }

                if (input[index] == '{' || input[index] == '[' || input[index] == '\"')
                {
                    PrimitiveJSONObject sub = new PrimitiveJSONObject();
                    index = sub.Read(input, index);
                    Content[key] = sub;

                    if (input[index] == ',')
                    {
                        index++;
                    }
                }
                else
                {
                    int index2 = input.IndexOf(',', index);
                    Content[key] = new PrimitiveJSONObject("\"" + input.Substring(index, index2 - index) + "\"", 0);
                    index = index2 + 1;
                }
            }
        }
Beispiel #2
0
 private int ReadArray(string input, int index)
 {
     index++;
     List<PrimitiveJSONObject> objects = new List<PrimitiveJSONObject>();
     while (true)
     {
         if (input[index] == '{' || input[index] == '[' || input[index] == '\"')
         {
             PrimitiveJSONObject sub = new PrimitiveJSONObject();
             index = sub.Read(input, index);
             objects.Add(sub);
             if (input[index] == ',')
             {
                 index++;
             }
         }
         else if (input[index] == ']')
         {
             index++;
             break;
         }
         else
         {
             throw new Exception("Bad JSON format.");
         }
     }
     Array = objects.ToArray();
     return index;
 }