public static string GetStringValue(JsonObject field) { if ((field == null) || (field.GetValue() == null)) { return null; } string str = null; string name = field.GetValue().GetType().Name; if (name == null) { return str; } if (!(name == "String")) { if (name != "Double") { if (name != "Boolean") { return str; } return field.GetValue().ToString(); } } else { return (string)field.GetValue(); } return field.GetValue().ToString(); }
private static Object ParseJson(JsonObject jsonObject) { Type type = jsonObject.GetType(); if (type == typeof(JsonObjectCollection)) { Hashtable val = new Hashtable(); foreach (JsonObject subObj in (jsonObject as JsonObjectCollection)) { val.Add(subObj.Name, ParseJson(subObj)); } if (val.ContainsKey("__DataType")) { if (val["__DataType"] as string == "Date") { return BaseDateTime.AddMilliseconds((Double)val["__Value"]); } else if (val["__DataType"] as string == "Exception") { return new Exception((val["__Value"] as Hashtable)["Message"] as string); } else { return val; } } else { return val; } } else if (type == typeof(JsonArrayCollection)) { List<object> val = new List<object>(); foreach (JsonObject subObj in (jsonObject as JsonArrayCollection)) { val.Add(ParseJson(subObj)); } return val.ToArray(); } else if (type == typeof(JsonBooleanValue)) { return jsonObject.GetValue(); } else if (type == typeof(JsonStringValue)) { return jsonObject.GetValue(); } else if (type == typeof(JsonNumericValue)) { return jsonObject.GetValue(); } else return null; }