Пример #1
0
 private void SkipWhitespace()
 {
     while (true)
     {
         int num = reader.Peek();
         if (num == -1 || !char.IsWhiteSpace((char)num))
         {
             break;
         }
         reader.Read();
     }
 }
 //---------------------------------------------------------------------------------
 // SkipWhitespace
 //---------------------------------------------------------------------------------
 private void SkipWhitespace()
 {
     while (true)
     {
         int peek = reader.Peek();
         if (peek == -1 || !Char.IsWhiteSpace((char)peek))
         {
             return;
         }
         reader.Read();
     }
 }
Пример #3
0
    //---------------------------------------------------------------------------------
    // ReadObject
    //---------------------------------------------------------------------------------
    private JSONNode ReadObject()
    {
        JSONNode node = new JSONNode();

        SkipWhitespace();
        // read '{'
        if (reader.Peek() != '{')
        {
            Debug.LogError("malformed json: no starting '{'");
            return(null);
        }
        reader.Read();
        while (reader.Peek() != '}')
        {
            if (reader.Peek() == ',')
            {
                reader.Read();
            }
            if (reader.Peek() == '}')
            {
                break;
            }

            SkipWhitespace();
            // read field name
            string fieldName = ReadFieldName().Trim();

            // read ':'
            SkipWhitespace();
            reader.Read();
            //Console.WriteLine("after : found " + ((char) reader.Peek()));

            // read value
            IJSONFieldValue val = ReadValue();

            //Console.WriteLine("adding field " + fieldName + " " + val);
            node.AddField(fieldName, val);
            SkipWhitespace();
        }
        reader.Read();         // remove trailing "}"

        return(node);
    }
Пример #4
0
    private JSONNode ReadObject()
    {
        JSONNode jSONNode = new JSONNode();

        SkipWhitespace();
        if (reader.Peek() != 123)
        {
            Debug.LogError((object)"malformed json: no starting '{'");
            return(null);
        }
        reader.Read();
        while (reader.Peek() != 125)
        {
            if (reader.Peek() == 44)
            {
                reader.Read();
            }
            if (reader.Peek() == 125)
            {
                break;
            }
            SkipWhitespace();
            string fieldName = ReadFieldName().Trim();
            SkipWhitespace();
            reader.Read();
            IJSONFieldValue val = ReadValue();
            jSONNode.AddField(fieldName, val);
            SkipWhitespace();
        }
        reader.Read();
        return(jSONNode);
    }