public static void ParseValue(JsonTextReader reader, Json.Value root, bool in_object) { string last_key = ""; Json.Value new_object = null; while (reader.Read() == true) { if (reader.TokenType == JsonToken.EndObject || reader.TokenType == JsonToken.EndArray) { break; } switch (reader.TokenType) { case JsonToken.StartObject: new_object = new Json.Object(); ParseValue(reader, new_object, true); break; case JsonToken.StartArray: new_object = new Json.Array(); ParseValue(reader, new_object, false); break; case JsonToken.PropertyName: last_key = (string)reader.Value; continue; case JsonToken.String: case JsonToken.Integer: case JsonToken.Null: object v = reader.Value; new_object = new Json.String(v == null ? "null" : v.ToString()); break; } if (root == null) { root = new_object; } if (in_object == true) { ((Json.Object)root).Add(last_key, new_object); continue; } ((Json.Array)root).Add(new_object); } }
public static Json.Value ParseValue(JsonTextReader reader) { reader.Read(); // Read first opening bracket Json.Value root = null; bool in_object = false; if (reader.TokenType == JsonToken.StartArray) { root = new Json.Array(); in_object = false; } else { root = new Json.Object(); in_object = true; } ParseValue(reader, root, in_object); return(root); }