Json解析错误:未处理的对象在字符275处

时间:2017-05-27 14:22:42

标签: android json

我的代码已经从网站获取数据(jsonstr)但无法使其成为JSONObject并且它会导致错误Json解析错误:字符2755处的未终止对象

protected Void doInBackground(Void... arg0) {
            HttpHandler sh = new HttpHandler();

            // Making a request to url and getting response
            String jsonStr = sh.makeServiceCall(url);

            Log.e(TAG, "Response from url: " + jsonStr);

            if (jsonStr != null) {
                try {
                    JSONObject jsonObj = new JSONObject(jsonStr);

                    // Getting JSON Array node
                    JSONArray contacts = jsonObj.getJSONArray("Destinasi");

                    // looping through All Contacts
                    for (int i = 0; i < contacts.length(); i++) {
                        JSONObject c = contacts.getJSONObject(i);

                        String nim = c.getString("nama_destinasi");
                        String name = c.getString("alamat_destinasi");
                        String alamat= c.getString("deskripsi_destinasi");

和我试图解析的这个链接 https://ombajuom.000webhostapp.com/json_destinasi.php/Destinasi

请帮助我,对不起我的英语

2 个答案:

答案 0 :(得分:1)

我在JSON字符串中看到错误的 ] } 。它返回的字符串 NOW 如下

{
   "Destinasi": [
      {
         "nomor_id": "1",
         "nama_destinasi": "Ravi Tamada",
         "alamat_destinasi": "Ciledug",
         "deskripsi_destinasi": "WAhhh",
         "rating_destinasi": "3"
      ]
   }
}

但它应该如下所示,使其成为有效的JSON。

{
   "Destinasi": [
      {
         "nomor_id": "1",
         "nama_destinasi": "Ravi Tamada",
         "alamat_destinasi": "Ciledug",
         "deskripsi_destinasi": "WAhhh",
         "rating_destinasi": "3"
      }
   ]
}

答案 1 :(得分:0)

您共享的Web服务不是有效的JSON格式,要验证您的响应,您可以使用jsonlint.com,

由于