Java replaces the control characters in JSON.

Source: Internet
Author: User

There is a piece of JSON

{

"Content": "The first time I sent it, my aunt came to see me, but my husband was not honest, holding me and touching it... finally, I reached out to the following... I opened it and asked him what he was doing... he blinked innocently: I see if my aunt's bed is good... ",
}

There is no error in Java, but in other places such

Http://jsonlint.com/

JSON parsing error reported here

Let's take a look at the above text. There is an invisible control character between "Me And ke ".

Write a method to replace these control characters.

Public static string filtercontrolascii (string Str ){

Stringbuilder sb = new stringbuilder ();
Int SZ = Str. Length ();
For (INT I = 0; I <SZ; I ++ ){
If (charutils. isasciicontrol (Str. charat (I) = false ){
SB. append (Str. charat (I ));
}
}

Return sb. tostring ();

}

That's all.

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.