/// <summary> /// Converts a Hashtable / ArrayList / Dictionary(string,string) object into a JSON string /// </summary> /// <param name="json">A Hashtable / ArrayList</param> /// <returns>A JSON encoded string, or null if object 'json' is not serializable</returns> public static string jsonEncode(object json) { var builder = new StringBuilder(BUILDER_CAPACITY); var success = MiniJSONParser.serializeValue(json, builder); return(success ? builder.ToString() : null); }
/// <summary> /// Parses the string json into a value /// </summary> /// <param name="json">A JSON string.</param> /// <returns>An ArrayList, a Hashtable, a double, a string, null, true, or false</returns> public static object jsonDecode(string json) { // save the string for debug information MiniJSONParser.lastDecode = json; if (json != null) { char[] charArray = json.ToCharArray(); int index = 0; bool success = true; object value = MiniJSONParser.parseValue(charArray, ref index, ref success); if (success) { MiniJSONParser.lastErrorIndex = -1; } else { MiniJSONParser.lastErrorIndex = index; } return(value); } else { return(null); } }
public static Hashtable hashtableFromJson(this string json) { return(MiniJSONParser.jsonDecode(json) as Hashtable); }
public static ArrayList arrayListFromJson(this string json) { return(MiniJSONParser.jsonDecode(json) as ArrayList); }
public static string toJson(this Dictionary <string, string> obj) { return(MiniJSONParser.jsonEncode(obj)); }
public static string toJson(this Hashtable obj) { return(MiniJSONParser.jsonEncode(obj)); }