private IDictionary<string, object> ReadObjectValue(JsonReader jsonReader) { this.IncreaseRecursionDepth(); IDictionary<string, object> dictionary = new Dictionary<string, object>(StringComparer.Ordinal); jsonReader.ReadNext(); while (jsonReader.NodeType != JsonNodeType.EndObject) { string key = jsonReader.ReadPropertyName(); object obj2 = null; switch (jsonReader.NodeType) { case JsonNodeType.StartObject: obj2 = this.ReadObjectValue(jsonReader); break; case JsonNodeType.StartArray: obj2 = this.ReadArrayValue(jsonReader); break; case JsonNodeType.PrimitiveValue: obj2 = jsonReader.ReadPrimitiveValue(); break; default: return null; } dictionary.Add(key, obj2); } jsonReader.ReadEndObject(); this.DecreaseRecursionDepth(); return dictionary; }
/// <summary> /// Reads the json object value from the jsonReader /// </summary> /// <param name="jsonReader">Json reader to read payload from the wire.</param> /// <returns>an instance of IDictionary containing the spatial value.</returns> private IDictionary<string, object> ReadObjectValue(JsonReader jsonReader) { Debug.Assert(jsonReader != null, "jsonReader != null"); Debug.Assert(jsonReader.NodeType == JsonNodeType.StartObject, "jsonReader.NodeType == JsonNodeType.StartObject"); this.IncreaseRecursionDepth(); IDictionary<string, object> jsonValue = new Dictionary<string, object>(StringComparer.Ordinal); jsonReader.ReadNext(); while (jsonReader.NodeType != JsonNodeType.EndObject) { // read the property name string propertyName = jsonReader.ReadPropertyName(); // read the property value object propertyValue = null; switch (jsonReader.NodeType) { case JsonNodeType.PrimitiveValue: propertyValue = jsonReader.ReadPrimitiveValue(); break; case JsonNodeType.StartArray: propertyValue = this.ReadArrayValue(jsonReader); break; case JsonNodeType.StartObject: propertyValue = this.ReadObjectValue(jsonReader); break; default: Debug.Assert(false, "We should never reach here - There should be matching end element"); return null; } jsonValue.Add(propertyName, propertyValue); } jsonReader.ReadEndObject(); this.DecreaseRecursionDepth(); return jsonValue; }