A JSONObject text must begin with '{' at 1 [character 2 line 1] with '{' error

前端 未结 12 791
失恋的感觉
失恋的感觉 2021-01-01 13:34
String JSON = \"http://www.json-generator.com/j/cglqaRcMSW?indent=4\";

JSONObject jsonObject = new JSONObject(JSON);
JSONObject getSth = jsonObject.getJSONObject(\"         


        
12条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-01 14:10

    In my case the json file encoding was a problem

    I was generating JSON file in vb .net with following: My.Computer.FileSystem.WriteAllText("newComponent.json", json.Trim, False)

    And I tried all suggestions in this post but none helped.

    Eventually in Notepad++ noticed that the file created was in UTF-8-BOM

    Not sure how it picked up that encoding but after I switched the encoding to UTF-8, it resolved with no other changes.

    Hope this helps someone.

提交回复
热议问题