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

前端 未结 12 575
失恋的感觉
失恋的感觉 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:18

    I had same issue. My Json response from the server was having [, and, ]:

    [{"DATE_HIRED":852344800000,"FRNG_SUB_ACCT":0,"MOVING_EXP":0,"CURRENCY_CODE":"CAD  ","PIN":"          ","EST_REMUN":0,"HM_DIST_CO":1,"SICK_PAY":0,"STAND_AMT":0,"BSI_GROUP":"           ","LAST_DED_SEQ":36}]
    

    http://jsonlint.com/ says valid json. you can copy and verify it.

    I have fixed with below code as temporary solution:

    BufferedReader br = new BufferedReader(new InputStreamReader((response.getEntity().getContent())));
    String result ="";
    String output = null;
    while ((result = br.readLine()) != null) {
        output = result.replace("[", "").replace("]", "");
        JSONObject jsonObject = new JSONObject(output); 
        JSONArray jsonArray = new JSONArray(output); 
        .....   
    }
    

提交回复
热议问题