Пример #1
0
        private static JsonArray ParseArray(StringReader stringReader)
        {
            stringReader.Read();
            JsonArray jsonArray = new JsonArray();

            while (stringReader.Peek() > -1)
            {
                if (stringReader.Peek() == ']')
                {
                    stringReader.Read();
                    return(jsonArray);
                }
                else
                {
                    jsonArray.Add(ParseValue(stringReader));
                }
            }
            return(jsonArray);
        }
        public string Stringify()
        {
            JsonArray jsonArray = new JsonArray();

            foreach (School school in Education)
            {
                jsonArray.Add(school.ToJsonObject());
            }

            JsonObject jsonObject = new JsonObject();

            jsonObject[idKey]        = JsonValue.CreateStringValue(Id);
            jsonObject[nameKey]      = JsonValue.CreateStringValue(Name);
            jsonObject[educationKey] = jsonArray;
            jsonObject[timezoneKey]  = JsonValue.CreateNumberValue(Timezone);
            jsonObject[verifiedKey]  = JsonValue.CreateBooleanValue(Verified);

            return(jsonObject.Stringify());
        }
Пример #3
0
        public object ParseSubtree()
        {
            IList <object> l = null;
            IDictionary <string, object> d = null;
            string rv;
            object result = null;

            switch (_state)
            {
            case -2:
                return(null);

            case -1:
                if (!Read())
                {
                    _pc.Expecting();
                }
                return(ParseSubtree());

            case 0:
                result = Value;
                break;

            case 1:                     // key
                rv = Value as string;
                if (!Read())
                {
                    _pc.Expecting();
                }
                result = new KeyValuePair <string, object>(rv, ParseSubtree());
                break;

            case 2:                    // begin array
                l = new JsonArray();
                while (Read() && 3 != _state)
                {
                    l.Add(ParseSubtree());
                }
                result = l;
                break;

            case 3:                     // end array
                result = null;
                break;

            case 4:                           // begin object
                d = new JsonObject();
                while (Read() && 5 != _state) // not end object
                {
                    KeyValuePair <string, object> kvp = (KeyValuePair <string, object>)ParseSubtree();
                    d.Add(kvp.Key, kvp.Value);
                }
                result = d;
                break;

            case 5:
                result = null;
                break;

            default:
                throw new InvalidProgramException("Unhandled state");
            }
            return(result);
        }