public static void SetJsonData(this DataMgr dataMgr, string key, JsonData data) { IJsonWrapper jsonWrapper = data; switch (data.GetJsonType()) { case JsonType.None: Debug.Log("jsondata is empty"); break; case JsonType.Object: SetObjectData(key, data); break; case JsonType.String: DataMgr.Instance.Set(key, jsonWrapper.GetString()); break; case JsonType.Int: DataMgr.Instance.Set(key, jsonWrapper.GetInt()); break; case JsonType.Long: DataMgr.Instance.Set(key, (int)jsonWrapper.GetLong()); break; case JsonType.Double: DataMgr.Instance.Set(key, (float)jsonWrapper.GetDouble()); break; } }
public static int AsInt32(this IJsonWrapper source, int defaultValue = 0) { if (source == null) { return(defaultValue); } switch (source.GetJsonType()) { case JsonType.Int: return(source.GetInt()); case JsonType.Long: return((int)source.GetLong()); case JsonType.Double: return((int)source.GetDouble()); case JsonType.Boolean: return(source.GetBoolean() ? 1 : 0); case JsonType.String: int value; if (int.TryParse(source.GetString(), out value)) { return(value); } break; case JsonType.Array: case JsonType.Object: return(source.Count); } return(defaultValue); }
public static double AsDouble(this IJsonWrapper source, double defaultValue = 0) { if (source == null) { return(defaultValue); } switch (source.GetJsonType()) { case JsonType.Double: return(source.GetDouble()); case JsonType.Int: return(source.GetInt()); case JsonType.Long: return(source.GetLong()); case JsonType.Boolean: return(source.GetBoolean() ? 1D : 0D); case JsonType.String: double value; if (double.TryParse(source.GetString(), out value)) { return(value); } break; case JsonType.Array: case JsonType.Object: return(source.Count); } return(defaultValue); }
public static ulong AsUInt64(this IJsonWrapper source, ulong defaultValue = 0) { if (source == null) { return(defaultValue); } switch (source.GetJsonType()) { case JsonType.Int: return((ulong)source.GetInt()); case JsonType.Long: return((ulong)source.GetLong()); case JsonType.Double: return((ulong)source.GetDouble()); case JsonType.Boolean: return(source.GetBoolean() ? 1UL : 0UL); case JsonType.String: ulong value; if (ulong.TryParse(source.GetString(), out value)) { return(value); } break; case JsonType.Array: case JsonType.Object: return((ulong)source.Count); } return(defaultValue); }
public static bool AsBoolean(this IJsonWrapper source, bool defaultValue = false) { if (source == null) { return(defaultValue); } switch (source.GetJsonType()) { case JsonType.Boolean: return(source.GetBoolean()); case JsonType.Int: return(source.GetInt() != 0); case JsonType.Long: return(source.GetLong() != 0); case JsonType.Double: return(source.GetDouble() != 0); case JsonType.String: bool value; if (bool.TryParse(source.GetString(), out value)) { return(value); } break; case JsonType.Array: case JsonType.Object: return(source.Count > 0); } return(defaultValue); }
public static ushort AsUInt16(this IJsonWrapper source, ushort defaultValue = 0) { if (source == null) { return(defaultValue); } switch (source.GetJsonType()) { case JsonType.Int: return((ushort)source.GetInt()); case JsonType.Long: return((ushort)source.GetLong()); case JsonType.Double: return((ushort)source.GetDouble()); case JsonType.Boolean: return(source.GetBoolean() ? (ushort)1 : (ushort)0); case JsonType.String: ushort value; if (ushort.TryParse(source.GetString(), out value)) { return(value); } break; case JsonType.Array: case JsonType.Object: return((ushort)source.Count); } return(defaultValue); }
public static void SetJsonData(this DataMgr mgr, string key, JsonData data) { IJsonWrapper jsonWrapper = data; switch (data.GetJsonType()) { case JsonType.None: Debug.Log("当前jsondata数据为空"); break; case JsonType.Object: SetObjectData(key, data); break; case JsonType.String: DataMgr.Single.Set(key, jsonWrapper.GetString()); break; case JsonType.Int: DataMgr.Single.Set(key, jsonWrapper.GetInt()); break; case JsonType.Long: DataMgr.Single.Set(key, (int)jsonWrapper.GetLong()); break; case JsonType.Double: DataMgr.Single.Set(key, (float)jsonWrapper.GetDouble()); break; default: throw new ArgumentOutOfRangeException(); } }
private static Document FromObject(IJsonWrapper jsonData) { switch (jsonData.GetJsonType()) { case JsonType.None: return(new Document()); case JsonType.Boolean: return(new Document(jsonData.GetBoolean())); case JsonType.Double: return(new Document(jsonData.GetDouble())); case JsonType.Int: return(new Document(jsonData.GetInt())); case JsonType.Long: return(new Document(jsonData.GetLong())); case JsonType.String: return(new Document(jsonData.GetString())); case JsonType.Array: return(new Document(jsonData.Values.OfType <object>().Select(FromObject).ToArray())); case JsonType.Object: var dictionary = new Dictionary <string, Document>(); Copy(jsonData, dictionary); return(new Document(dictionary)); } throw new NotSupportedException($"Couldn't convert {jsonData.GetJsonType()}"); }
public static sbyte AsInt8(this IJsonWrapper source, sbyte defaultValue = 0) { if (source == null) { return(defaultValue); } switch (source.GetJsonType()) { case JsonType.Int: return((sbyte)source.GetInt()); case JsonType.Long: return((sbyte)source.GetLong()); case JsonType.Double: return((sbyte)source.GetDouble()); case JsonType.Boolean: return(source.GetBoolean() ? (sbyte)1 : (sbyte)0); case JsonType.String: sbyte value; if (sbyte.TryParse(source.GetString(), out value)) { return(value); } break; case JsonType.Array: case JsonType.Object: return((sbyte)source.Count); } return(defaultValue); }
public static float AsSingle(this IJsonWrapper source, float defaultValue = 0) { if (source == null) { return(defaultValue); } switch (source.GetJsonType()) { case JsonType.Double: return((float)source.GetDouble()); case JsonType.Int: return(source.GetInt()); case JsonType.Long: return(source.GetLong()); case JsonType.Boolean: return(source.GetBoolean() ? 1F : 0F); case JsonType.String: if (float.TryParse(source.GetString(), out float value)) { return(value); } break; case JsonType.Array: case JsonType.Object: return(source.Count); } return(defaultValue); }
private static object ToBasePropertyValue(IJsonWrapper data) { if (data.IsBoolean) { return(data.GetBoolean()); } else if (data.IsDouble) { return(data.GetDouble()); } else if (data.IsInt) { return(data.GetInt()); } else if (data.IsLong) { return(data.GetLong()); } else if (data.IsString) { return(data.GetString()); } else { throw new NotImplementedException(); } }
private static void WriteJson(IJsonWrapper obj, JsonWriter writer, bool toHex = true) { if (obj == null) { writer.Write(null); } else if (obj.IsString) { writer.Write(obj.GetString(), toHex); } else if (obj.IsBoolean) { writer.Write(obj.GetBoolean()); } else if (obj.IsDouble) { writer.Write(obj.GetDouble()); } else if (obj.IsInt) { writer.Write(obj.GetInt()); } else if (obj.IsLong) { writer.Write(obj.GetLong()); } else if (obj.IsArray) { writer.WriteArrayStart(); foreach (JsonData item in (IEnumerable)obj) { WriteJson(item, writer, toHex); } writer.WriteArrayEnd(); } else if (obj.IsObject) { writer.WriteObjectStart(); IDictionaryEnumerator enumerator2 = ((IDictionary)obj).GetEnumerator(); try { while (enumerator2.MoveNext()) { DictionaryEntry dictionaryEntry = (DictionaryEntry)enumerator2.Current; writer.WritePropertyName((string)dictionaryEntry.Key); WriteJson((JsonData)dictionaryEntry.Value, writer, toHex); } } finally { IDisposable disposable = enumerator2 as IDisposable; if (disposable != null) { disposable.Dispose(); } } writer.WriteObjectEnd(); } }
private static void WriteJson(IJsonWrapper obj, JsonWriter writer) { if (obj.IsString) { writer.Write(obj.GetString()); return; } if (obj.IsBoolean) { writer.Write(obj.GetBoolean()); return; } if (obj.IsDouble) { writer.Write(obj.GetDouble()); return; } if (obj.IsInt) { writer.Write(obj.GetInt()); return; } if (obj.IsLong) { writer.Write(obj.GetLong()); return; } if (obj.IsArray) { writer.WriteArrayStart(); foreach (object elem in (IList)obj) { WriteJson((JsonData)elem, writer); } writer.WriteArrayEnd(); return; } if (obj.IsObject) { writer.WriteObjectStart(); foreach (DictionaryEntry entry in ((IDictionary)obj)) { writer.WritePropertyName((string)entry.Key); WriteJson((JsonData)entry.Value, writer); } writer.WriteObjectEnd(); return; } }
private static void WriteJson(IJsonWrapper obj, JsonWriter writer) { if (obj == null) { writer.Write(null); return; } if (obj.IsString) { writer.Write(obj.GetString()); return; } if (obj.IsBoolean) { writer.Write(obj.GetBoolean()); return; } if (obj.IsDouble) { writer.Write(obj.GetDouble()); return; } if (obj.IsInt) { writer.Write(obj.GetInt()); return; } if (obj.IsLong) { writer.Write(obj.GetLong()); return; } if (obj.IsArray) { writer.WriteArrayStart(); foreach (object current in obj) { JsonData.WriteJson((JsonData)current, writer); } writer.WriteArrayEnd(); return; } if (obj.IsObject) { writer.WriteObjectStart(); foreach (DictionaryEntry dictionaryEntry in obj) { writer.WritePropertyName((string)dictionaryEntry.Key); JsonData.WriteJson((JsonData)dictionaryEntry.Value, writer); } writer.WriteObjectEnd(); return; } }
private void CloneFromJsonWrapper(IJsonWrapper jsonWrapper) { JsonData jsonData = jsonWrapper as JsonData; if (jsonData != null) { type = jsonData.type; json = jsonData.json; inst_boolean = jsonData.inst_boolean; inst_double = jsonData.inst_double; inst_int = jsonData.inst_int; inst_long = jsonData.inst_long; inst_string = jsonData.inst_string; if (jsonData.inst_array != null) { inst_array = new List <JsonData>(jsonData.inst_array); } if (jsonData.inst_object != null) { inst_object = new Dictionary <string, JsonData>(jsonData.inst_object); } return; } type = jsonWrapper.GetJsonType(); switch (type) { case JsonType.Boolean: inst_boolean = jsonWrapper.GetBoolean(); break; case JsonType.Int: inst_int = jsonWrapper.GetInt(); break; case JsonType.Long: inst_long = jsonWrapper.GetLong(); break; case JsonType.Double: inst_double = jsonWrapper.GetDouble(); break; case JsonType.String: inst_string = jsonWrapper.GetString(); break; case JsonType.Array: SetJsonType(JsonType.Array); foreach (object item in jsonWrapper as IList) { Add(item as JsonData ?? new JsonData(item)); } break; case JsonType.Object: SetJsonType(JsonType.Object); foreach (DictionaryEntry item in jsonWrapper as IDictionary) { this[item.Key.ToString()] = item.Value as JsonData ?? new JsonData(item.Value); } break; } }
private static void a(IJsonWrapper A_0, JsonWriter A_1) { if (A_0 == null) { A_1.Write(null); return; } if (A_0.IsString) { A_1.Write(A_0.GetString()); return; } if (A_0.IsBoolean) { A_1.Write(A_0.GetBoolean()); return; } if (A_0.IsDouble) { A_1.Write(A_0.GetDouble()); return; } if (A_0.IsInt) { A_1.Write(A_0.GetInt()); return; } if (A_0.IsLong) { A_1.Write(A_0.GetLong()); return; } if (A_0.IsArray) { A_1.WriteArrayStart(); foreach (object current in A_0) { JsonData.a((JsonData)current, A_1); } A_1.WriteArrayEnd(); return; } if (A_0.IsObject) { A_1.WriteObjectStart(); foreach (DictionaryEntry dictionaryEntry in A_0) { A_1.WritePropertyName((string)dictionaryEntry.Key); JsonData.a((JsonData)dictionaryEntry.Value, A_1); } A_1.WriteObjectEnd(); } }
private static void WriteJson(IJsonWrapper obj, JsonWriter writer) { if (obj.IsString) { writer.Write(obj.GetString()); } else if (obj.IsBoolean) { writer.Write(obj.GetBoolean()); } else if (obj.IsDouble) { writer.Write(obj.GetDouble()); } else if (obj.IsInt) { writer.Write(obj.GetInt()); } else if (obj.IsUint) { writer.Write(obj.GetUint()); } else if (obj.IsLong) { writer.Write(obj.GetLong()); } else if (obj.IsArray) { writer.WriteArrayStart(); foreach (object current in (IList)obj) { JsonData.WriteJson((JsonData)current, writer); } writer.WriteArrayEnd(); } else if (obj.IsObject) { writer.WriteObjectStart(); foreach (DictionaryEntry dictionaryEntry in (IDictionary)obj) { writer.WritePropertyName((string)dictionaryEntry.Key); JsonData.WriteJson((JsonData)dictionaryEntry.Value, writer); } writer.WriteObjectEnd(); } else if (obj.GetJsonType() == JsonType.None) { //为空的情况下,也要能写一对花括号,避免格式出错。 writer.WriteObjectStart(); writer.WriteObjectEnd(); } }
private static void WriteJson(IJsonWrapper obj, JsonWriter writer, bool toHex = true) { if (obj == null) { writer.Write((string)null, true); } else if (obj.IsString) { writer.Write(obj.GetString(), toHex); } else if (obj.IsBoolean) { writer.Write(obj.GetBoolean()); } else if (obj.IsDouble) { writer.Write(obj.GetDouble()); } else if (obj.IsInt) { writer.Write(obj.GetInt()); } else if (obj.IsLong) { writer.Write(obj.GetLong()); } else if (obj.IsArray) { writer.WriteArrayStart(); foreach (IJsonWrapper jsonWrapper in (IEnumerable)obj) { JsonData.WriteJson(jsonWrapper, writer, toHex); } writer.WriteArrayEnd(); } else { if (!obj.IsObject) { return; } writer.WriteObjectStart(); foreach (DictionaryEntry dictionaryEntry in (IDictionary)obj) { writer.WritePropertyName((string)dictionaryEntry.Key); JsonData.WriteJson((IJsonWrapper)dictionaryEntry.Value, writer, toHex); } writer.WriteObjectEnd(); } }
private static void WriteJson(IJsonWrapper obj, JsonWriter writer) { if (obj == null) { writer.Write(null); } else if (obj.IsString) { writer.Write(obj.GetString()); } else if (obj.IsBoolean) { writer.Write(obj.GetBoolean()); } else if (obj.IsDouble) { writer.Write(obj.GetDouble()); } else if (obj.IsInt) { writer.Write(obj.GetInt()); } else if (obj.IsLong) { writer.Write(obj.GetLong()); } else if (obj.IsArray) { writer.WriteArrayStart(); foreach (object item in (IEnumerable)obj) { WriteJson((JsonData)item, writer); } writer.WriteArrayEnd(); } else { if (!obj.IsObject) { return; } writer.WriteObjectStart(); foreach (DictionaryEntry item2 in (IDictionary)obj) { writer.WritePropertyName((string)item2.Key); WriteJson((JsonData)item2.Value, writer); } writer.WriteObjectEnd(); } }
public static double GetJsonDouble(this JsonData data) { IJsonWrapper id = data; if (id.IsInt) { return(id.GetInt()); } else if (id.IsLong) { return(id.GetLong()); } return(id.GetDouble()); }
public static string AsString(this IJsonWrapper source, string defaultValue = "") { if (source == null) { return(defaultValue); } switch (source.GetJsonType()) { case JsonType.String: return(source.GetString()); case JsonType.Double: return(source.GetDouble().ToString()); case JsonType.Int: return(source.GetInt().ToString()); case JsonType.Long: return(source.GetLong().ToString()); case JsonType.Boolean: return(source.GetBoolean().ToString()); case JsonType.Array: case JsonType.Object: return(source.Count.ToString()); } return(defaultValue); }
private static Document MapFromJsonObject(IJsonWrapper jsonWrapper) { if (null == jsonWrapper) { return(new Document()); } switch (jsonWrapper.GetJsonType()) { case JsonType.None: return(new Document()); case JsonType.Boolean: return(new Document(jsonWrapper.GetBoolean())); case JsonType.Double: return(new Document(jsonWrapper.GetDouble())); case JsonType.Int: return(new Document(jsonWrapper.GetInt())); case JsonType.Long: return(new Document(jsonWrapper.GetLong())); case JsonType.String: return(new Document(jsonWrapper.GetString())); case JsonType.Array: return(new Document((jsonWrapper as IList).Cast <IJsonWrapper>().Select(MapFromJsonObject).ToList())); case JsonType.Object: return(new Document(MapDictionary(jsonWrapper))); default: throw new ArgumentException($"Unknown JSON type: {jsonWrapper.GetJsonType()}"); } }
private static void WriteJson(IJsonWrapper obj, JsonWriter writer) { if (obj.IsString) { writer.Write (obj.GetString ()); return; } if (obj.IsBoolean) { writer.Write (obj.GetBoolean ()); return; } if (obj.IsDouble) { writer.Write (obj.GetDouble ()); return; } if (obj.IsInt) { writer.Write (obj.GetInt ()); return; } if (obj.IsLong) { writer.Write (obj.GetLong ()); return; } if (obj.IsArray) { writer.WriteArrayStart (); foreach (object elem in (IList) obj) WriteJson ((JsonData) elem, writer); writer.WriteArrayEnd (); return; } if (obj.IsObject) { writer.WriteObjectStart (); foreach (DictionaryEntry entry in ((IDictionary) obj)) { writer.WritePropertyName ((string) entry.Key); WriteJson ((JsonData) entry.Value, writer); } writer.WriteObjectEnd (); return; } }
// Token: 0x060156C5 RID: 87749 RVA: 0x0056E690 File Offset: 0x0056C890 private static void WriteJson(IJsonWrapper obj, JsonWriter writer) { if (obj.IsString) { writer.Write(obj.GetString()); return; } if (obj.IsBoolean) { writer.Write(obj.GetBoolean()); return; } if (obj.IsDouble) { writer.Write(obj.GetDouble()); return; } if (obj.IsInt) { writer.Write(obj.GetInt()); return; } if (obj.IsLong) { writer.Write(obj.GetLong()); return; } if (obj.IsArray) { writer.WriteArrayStart(); IEnumerator enumerator = obj.GetEnumerator(); try { while (enumerator.MoveNext()) { object obj2 = enumerator.Current; JsonData.WriteJson((JsonData)obj2, writer); } } finally { IDisposable disposable; if ((disposable = (enumerator as IDisposable)) != null) { disposable.Dispose(); } } writer.WriteArrayEnd(); return; } if (obj.IsObject) { writer.WriteObjectStart(); IDictionaryEnumerator enumerator2 = obj.GetEnumerator(); try { while (enumerator2.MoveNext()) { object obj3 = enumerator2.Current; DictionaryEntry dictionaryEntry = (DictionaryEntry)obj3; writer.WritePropertyName((string)dictionaryEntry.Key); JsonData.WriteJson((JsonData)dictionaryEntry.Value, writer); } } finally { IDisposable disposable2; if ((disposable2 = (enumerator2 as IDisposable)) != null) { disposable2.Dispose(); } } writer.WriteObjectEnd(); return; } }
private static void WriteJson(IJsonWrapper obj, JsonWriter writer, bool indent = true) { if (obj == null) { writer.Write(null); return; } if (obj.IsString) { writer.Write(obj.GetString()); return; } if (obj.IsBoolean) { writer.Write(obj.GetBoolean()); return; } if (obj.IsDouble) { writer.Write(obj.GetDouble()); return; } if (obj.IsInt) { writer.Write(obj.GetInt()); return; } if (obj.IsLong) { writer.Write(obj.GetLong()); return; } if (obj.IsArray) { bool isPretty = writer.PrettyPrint; writer.PrettyPrint = true; writer.WriteArrayStart(indent); writer.PrettyPrint = false; foreach (object elem in (IList)obj) { WriteJson((JsonData)elem, writer, false); } writer.PrettyPrint = isPretty; writer.WriteArrayEnd(indent); return; } if (obj.IsObject) { writer.WriteObjectStart(); foreach (DictionaryEntry entry in ((IDictionary)obj)) { writer.WritePropertyName((string)entry.Key); WriteJson((JsonData)entry.Value, writer); } writer.WriteObjectEnd(); return; } }
private static void WriteJson(IJsonWrapper obj, JsonWriter writer) { if (obj.IsString) { writer.Write(obj.GetString()); return; } if (obj.IsBoolean) { writer.Write(obj.GetBoolean()); return; } if (obj.IsDouble) { writer.Write(obj.GetDouble()); return; } if (obj.IsInt) { writer.Write(obj.GetInt()); return; } if (obj.IsLong) { writer.Write(obj.GetLong()); return; } if (obj.IsArray) { writer.WriteArrayStart(); { // foreach(var elem in (IList) obj) var __enumerator3 = ((IList)obj).GetEnumerator(); while (__enumerator3.MoveNext()) { var elem = (object)__enumerator3.Current; WriteJson((JsonData)elem, writer); } } writer.WriteArrayEnd(); return; } if (obj.IsObject) { writer.WriteObjectStart(); { // foreach(var entry in ((IDictionary) obj)) var __enumerator4 = (((IDictionary)obj)).GetEnumerator(); while (__enumerator4.MoveNext()) { var entry = (DictionaryEntry)__enumerator4.Current; { writer.WritePropertyName((string)entry.Key); WriteJson((JsonData)entry.Value, writer); } } } writer.WriteObjectEnd(); return; } }
private static void WriteJson(IJsonWrapper wrapper, JsonWriter writer) { if (wrapper == null && !JsonWriter.SkipNullMember) { writer.Write(null); return; } if (wrapper.IsString) { writer.Write(wrapper.GetString()); return; } if (wrapper.IsBoolean) { writer.Write(wrapper.GetBoolean()); return; } if (wrapper.IsDouble) { writer.Write(wrapper.GetDouble()); return; } if (wrapper.IsInt) { writer.Write(wrapper.GetInt()); return; } if (wrapper.IsFloat) { writer.Write(wrapper.GetFloat()); return; } if (wrapper.IsLong) { writer.Write(wrapper.GetLong()); return; } if (wrapper.IsArray) { writer.WriteArrayStart(); foreach (var elem in (IList)wrapper) { WriteJson((JsonData)elem, writer); } writer.WriteArrayEnd(); return; } if (wrapper.IsObject) { if (JsonWriter.SkipNullMember && wrapper.Count <= 0) { return; } writer.WriteObjectStart(); foreach (DictionaryEntry entry in (IDictionary)wrapper) { if (JsonWriter.SkipNullMember) { var type = ((JsonData)entry.Value).GetJsonType(); if (type == JsonType.None) { continue; } if (type == JsonType.Array && ((IList)entry.Value).Count <= 0) { continue; } } writer.WritePropertyName((string)entry.Key); WriteJson((JsonData)entry.Value, writer); } writer.WriteObjectEnd(); return; } if (wrapper.GetJsonType() == JsonType.None) { writer.WriteObjectStart(); writer.WriteObjectEnd(); } }
private static void WriteJson(IJsonWrapper obj, JsonWriter writer) { if (obj == null) { writer.Write((string)null); } else if (obj.IsString) { writer.Write(obj.GetString()); } else if (obj.IsBoolean) { writer.Write(obj.GetBoolean()); } else if (obj.IsDouble) { writer.Write(obj.GetDouble()); } else if (obj.IsInt) { writer.Write(obj.GetInt()); } else if (obj.IsLong) { writer.Write(obj.GetLong()); } else if (obj.IsArray) { writer.WriteArrayStart(); IEnumerator enumerator = obj.GetEnumerator(); try { while (enumerator.MoveNext()) { object current = enumerator.Current; WriteJson((JsonData)current, writer); } } finally { IDisposable disposable = enumerator as IDisposable; if (disposable == null) { } disposable.Dispose(); } writer.WriteArrayEnd(); } else if (obj.IsObject) { writer.WriteObjectStart(); IDictionaryEnumerator enumerator2 = obj.GetEnumerator(); try { while (enumerator2.MoveNext()) { DictionaryEntry entry = (DictionaryEntry)enumerator2.Current; writer.WritePropertyName((string)entry.Key); WriteJson((JsonData)entry.Value, writer); } } finally { IDisposable disposable2 = enumerator2 as IDisposable; if (disposable2 == null) { } disposable2.Dispose(); } writer.WriteObjectEnd(); } }
private static void WriteJson(IJsonWrapper wrapper, JsonWriter writer) { if (wrapper == null) { writer.Write(null); return; } if (wrapper.IsString) { writer.Write(wrapper.GetString()); return; } if (wrapper.IsBoolean) { writer.Write(wrapper.GetBoolean()); return; } if (wrapper.IsDouble) { writer.Write(wrapper.GetDouble()); return; } if (wrapper.IsInt) { writer.Write(wrapper.GetInt()); return; } if (wrapper.IsLong) { writer.Write(wrapper.GetLong()); return; } if (wrapper.IsArray) { writer.WriteArrayStart(); foreach (object elem in (IList)wrapper) { WriteJson((JsonData)elem, writer); } writer.WriteArrayEnd(); return; } if (wrapper.IsObject) { if (((IDictionary)wrapper).Count <= 0) { return; } writer.WriteObjectStart(); foreach (DictionaryEntry entry in ((IDictionary)wrapper)) { //TODO: ignore null entry var data = (JsonData)entry.Value; var type = data.GetJsonType(); if (type == JsonType.None) { continue; } if (type == JsonType.Array && ((IList)entry.Value).Count <= 0) { continue; } writer.WritePropertyName((string)entry.Key); WriteJson(data, writer); } writer.WriteObjectEnd(); return; } if (wrapper.GetJsonType() == JsonType.None) { writer.WriteObjectStart(); writer.WriteObjectEnd(); return; } }