Using org. json. JSONException: java. lang. stringcannotbeconvertedtoJSONObject: print the string and check whether the json string is correct. After studying it for a long time, I finally found the problem ,... syn is using org. json. JSONException: java. lang. string cannot be converted to JSONObject: print the String and check whether the json String is correct. After studying it for a long time, I finally found the problem. The cause is that when writing a json file, it adopts UTF-8 encoding and utf8 has a BOM format. It is okay to remove this format. How to remove it? Another way is to remove the BOM header in java code: [java] public static String JSONTokener (String in) {// consume an optional byte order mark (BOM) if it exists if (in! = Null & in. startsWith ("\ ufeff") {in = in. substring (1) ;}return in ;}
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