/// <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 JSON instance = new JSON(); instance.lastDecode = json; if (json != null) { char[] charArray = json.ToCharArray(); int index = 0; bool success = true; object value = instance.ParseValue(charArray, ref index, ref success); if (success) { instance.lastErrorIndex = -1; } else { instance.lastErrorIndex = index; } return value; } else { return null; } }
/// <summary> /// Converts a Hashtable / ArrayList 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) { StringBuilder builder = new StringBuilder(BUILDER_CAPACITY); bool success = new JSON().SerializeValue(json, builder); return (success ? builder.ToString() : null); }