A JSONArray text must start with '[' at 1 [character 2 line 1]

后端 未结 2 429
梦谈多话
梦谈多话 2021-01-01 06:06

I have a JSON file and i am trying to deal with but the following error is appears:

Exception in thread \"main\" org.json.JSONException: A JSONObject

2条回答
  •  一整个雨季
    2021-01-01 06:41

    You have to read the content of the file first, because the constructor of JSONArray needs the file-content and not the file-path.

    new JSONObject(new JSONTokener(new FileInputStream(new File("path"), "UTF-8")));
    
    new JSONObject(new JSONTokener(new FileReader("path")));
    

    update You should use a filereader or specify the charset for the FileInputStream

提交回复
热议问题