JSONException in java: java. lang. String cannot be converted to JSONObject

Source: Internet
Author: User

The following problems occur during JSON parsing in Android:

Org. json. JSONException: Value & # xFEFF; of type java. lang. String cannot be converted to JSONObject

When you use Notepad ++ to set file encoding, use utf8 encoding. The above problem occurs. The reason is that the file contains the utf8 bom header information. You can use utf8 without BOM encoding.

For specific settings, see the following figure:

Supplement: bom format processing

The code is as follows: Copy code
String st = "UTF-8 bom format String content ";
Byte [] bytes = st. getBytes ("UTF-8 ");
Byte [] strs = new byte [bytes. length-3]; // remove the bom label of the content
Int j = 0;
If (bytes [0] =-17 & bytes [1] =-69 & bytes [2] =-65) {// header bytes of the bom file format
For (int I = 3; I <bytes. length; I ++ ){
Strs [j] = bytes [I];
J ++;
}

This is why the encoding problem is the same as the bom format encoding in php.

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.