When using JSON, some special characters make us unable to wait for the expected results. The following filtering method uses the filtering method in Discuz to help us solve this problem. First, the js code that handles this problem is attached with the front-end code.
/// <Summary> /// load the event /// </summary> /// <param name = "sender"> </param> /// <param name = "e"> </param> protected void Page_Load (object sender, eventArgs e) {if (! IsPostBack) {FileStream fsSteam = new FileStream (Server. MapPath ("~ /SQLLog.txt "), FileMode. Open); // The text in SQLLog.txt is" happy "! StreamReader sr = new StreamReader (fsSteam, System. Text. Encoding. GetEncoding ("gb2312"); string message = JsonCharFilter (sr. ReadToEnd (); // The same in bytes. Sr. close (); fsSteam. dispose (); string json = "{IfSuccess: true, Message: '" + message + "'}"; this. ltMessage. text = json; }}/// <summary> // filter Json characters, see http://www.json.org//// </summary> /// <param name = "sourceStr"> source string to be filtered </param> /// <returns> returns the filtered string </returns> public static string JsonCharFilter (string sourceStr) {sourceStr = sourceStr. replace ("\", "\"); sourceStr = sourceStr. replace ("B", "\ B"); sourceStr = sourceStr. replace ("t", "\ t"); sourceStr = sourceStr. replace ("n", "\ n"); sourceStr = sourceStr. replace ("n", "\ n"); sourceStr = sourceStr. replace ("f", "\ f"); sourceStr = sourceStr. replace ("r", "\ r"); return sourceStr. replace (""","\"");}
Front-end code:
<Html xmlns = "http://www.w3.org/1999/xhtml">