JSON background processing of special character methods, processed at Jsonarray.fromobject conversion

Source: Internet
Author: User

Tag:array   class    Replacement    post   decode    reg   return   param   object   

/*** replaces some of the specified characters in a string * @param strdata String Raw String * @param regex string to be replaced by * @param replacement string Substitution String * @return S Tring replaced string */public static string replacestring (string strdata, string regex, string replacement) {if (strdata = = Nu    LL) {return null;    } int index;    index = Strdata.indexof (regex);    String strnew = "";            if (index >= 0) {while (index >= 0) {strnew + = strdata.substring (0, index) + replacement;            Strdata = strdata.substring (index + regex.length ());        index = Strdata.indexof (regex);        } strnew + = Strdata;    return strnew; } return strdata;}    /*** replaces the special character in the string */public the static string encodestring (String strdata) {if (strdata = null) {return "";    } strdata = Replacestring (Strdata, "&", "&");    Strdata = replacestring (Strdata, "<", "<");    Strdata = replacestring (strdata, ">", ">");    Strdata = replacestring (strdata, "'", "'"); Strdata = ReplacesTring (strdata, "\ \", "\\\\");//The Escape of the slash//strdata = replacestring (strdata, "\", "" "); Double quotes This may not be a special character return strdata;}    /*** restores a special character in a string */public static string decodestring (String strdata) {strdata = replacestring (Strdata, "<", "<");    Strdata = replacestring (strdata, ">", ">");    Strdata = replacestring (strdata, "'", "'");    Strdata = replacestring (Strdata, "" "," \ "");    Strdata = replacestring (Strdata, "&", "&"); return strdata;}

  

JSON background processing of special character methods, processed at Jsonarray.fromobject conversion

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.