/// <summary> ///Filter Special Characters/// </summary> Private Static stringString2json (String s) {StringBuilder sb=NewStringBuilder (); for(inti =0; i < s.length; i++) { Charc =S.tochararray () [i]; Switch(c) { Case '\"': SB. Append ("\\\""); Break; Case '\\': SB. Append ("\\\\"); Break; Case '/': SB. Append ("\\/"); Break; Case '\b': SB. Append ("\\b"); Break; Case '\f': SB. Append ("\\f"); Break; Case '\ n': SB. Append ("\\n"); Break; Case '\ r': SB. Append ("\\r"); Break; Case '\ t': SB. Append ("\\t"); Break; default: SB. Append (c); Break; } } returnsb. ToString (); }
/// <summary> ///format character, date, Boolean/// </summary> Private Static stringStringFormat (stringstr, type type) { if(Type = =typeof(string) ) {str=String2json (str); STR="\""+ str +"\""; } Else if(Type = =typeof(DateTime)) {STR="\""+ str +"\""; } Else if(Type = =typeof(BOOL) ) {str=Str. ToLower (); } Else if(Type! =typeof(string) &&string. IsNullOrEmpty (str)) {str="\""+ str +"\""; } returnstr; }
JSON conversion Class (i)--filter special characters, format character, date, Boolean