Org. json. JSONException: A JSONObject text must begin with & amp; #39 ;{& amp; #39; at character 1? {Solution

Source: Internet
Author: User

Exception in json parsing org. json. JSONException: A JSONObject text must begin with & #39 ;{& #39; at character 1? {Solution

The reason for this exception is that the json string format is not normal and does not end with "{" or "}". Check the json file format carefully to solve this problem. But sometimes the json file is normal, there is still this exception information, how to do it, this is because your json file header contains encoding characters (such as UTF-8 ), when reading a string, the json string is normal, but there is an exception in parsing. Generally, the json string is read from a server or a local file, and the file header contains the encoding, as far as I can see, Android2.1's mobile phone reports an exception. A phone number higher than 2.1 is normal.


Solution: Let's take a look at the differences between encoded files. Use UE to open json files with or without encoding, and switch to HEX mode, it is found that the encoded file contains three more bytes than the non-encoded file. when reading the encoded file, you only need to read the first three bytes so that the file can be parsed normally.
Files with UTF-8 Encoding:

 

Files without encoding:

Related Article

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.