About JSON parsing when the exception org.json.jsonexception:a Jsonobject text must begin with ' {' at character 1 of? { The workaround

Source: Internet
Author: User

This exception occurs because the JSON string is malformed, there is no "{" Start or no "}" end, a careful examination of the format of the JSON file will generally solve the problem. But sometimes the JSON file is normal, there is still this exception information, what to do, this is because your JSON file header with encoded characters (such as UTF-8, etc.), the JSON string is normal to read, but the parsing has an exception, Generally this occurs when the JSON string is read from the server or local files, the file in the header of the code, I encountered the situation in the Android2.1 phone will report abnormal, more than 2.1 of the phone is normal.


Workaround: We take a look at how the encoded file is different, with the UE open with encoded and non-encoded JSON file, and then switch to hex mode, you will find that the encoded file is three bytes more than the non-encoded file, read the encoded file as long as the first three bytes are not read, so that it can be parsed normally.
Files with UTF-8 encoding :



Files without encoding:


About JSON parsing when the exception org.json.jsonexception:a Jsonobject text must begin with ' {' at character 1 of? { The workaround

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.