サーバからJSONの配列を取得しています。しかし、私はそれにアクセスしようとしていますが、私はUnterminatedオブジェクトの例外を取得しています。JSON配列の終了していないオブジェクト例外を取得する
コンマが間違っているか間違っている構文の出力をチェックしましたが、まだ動作していません。配列から
JSON配列
[
{
"cust_id": "8",
"mer_id": "3",
"fav": "1",
"cont_name": "sandeep",
"kirana_name": "kasar",
"phone_no": "9422879610",
"email_id": "[email protected]",
"address": "nashik"
},
{
"cust_id": "8",
"mer_id": "1",
"fav": "1",
"cont_name": "sandeep",
"kirana_name": "general store",
"phone_no": "1212345623",
"email_id": "[email protected]",
"address": "nashik road nashik"
},
{
"cust_id": "8",
"mer_id": "5",
"fav": "0",
"cont_name": "a",
"kirana_name": "s",
"phone_no": "9422879610",
"email_id": "[email protected]",
"address": "aa"
},
{
"cust_id": "8",
"mer_id": "6",
"fav": "0",
"cont_name": "see ya",
"kirana_name": "see ya kirana",
"phone_no": "8698766460",
"email_id": "[email protected]",
"address": "dee"
},
{
"cust_id": "8",
"mer_id": "5",
"fav": "0",
"cont_name": "a",
"kirana_name": "s",
"phone_no": "9422879610",
"email_id": "[email protected]",
"address": "aa"
},
{
"cust_id": "8",
"mer_id": "9",
"fav": "0",
"cont_name": "fre",
"kirana_name": "fee kirana",
"phone_no": "8698766460",
"email_id": "[email protected]",
"address": "plotno:12,sahaydri nagar"
}
]
取得データ:
@Override
protected void onPostExecute(JSONObject response) {
super.onPostExecute(response);
progressDialog.dismiss();
try {
merchantsList.clear();
JSONArray jsonArray = response.getJSONArray("array");
if(jsonArray.length() > 0) {
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject jsonObject = jsonArray.getJSONObject(i);
if (jsonObject.has("message")) {
String message = jsonObject.getString("message");
Snackbar snackbar = Snackbar.make(coordinatorLayout, message, Snackbar.LENGTH_LONG);
snackbar.show();
} else {
long id,merchant_id,item_quantity;
String kirana_name,created_at,address;
int fav;
merchant_id=jsonObject.getLong("mer_id");
kirana_name=jsonObject.getString("kirana_name");
fav=jsonObject.getInt("fav");
address=jsonObject.getString("address");
Merchants merchants = new Merchants(merchant_id,kirana_name,address,fav);
merchantsList.add(merchants);
merchantsAdapter.notifyDataSetChanged();
}
}
}
例外:何が問題なのだろう
org.json.JSONException: Unterminated object at character 973 of {"array":[{"cust_id":"8","mer_id":"3","fav":"1","cont_name":"sandeep","kirana_name":"kasar","phone_no":"9422879610","email_id":"[email protected]","address":"nashik"},{"cust_id":"8","mer_id":"1","fav":"1","cont_name":"sandeep","kirana_name":"general store","phone_no":"1212345623","email_id":"[email protected]","address":"nashik road nashik"},{"cust_id":"8","mer_id":"5","fav":"0","cont_name":"a","kirana_name":"s","phone_no":"9422879610","email_id":"[email protected]","address":"aa"},{"cust_id":"8","mer_id":"6","fav":"0","cont_name":"see ya","kirana_name":"see ya kirana","phone_no":"8698766460","email_id":"[email protected]","address":"dee"},{"cust_id":"8","mer_id":"5","fav":"0","cont_name":"a","kirana_name":"s","phone_no":"9422879610","email_id":"[email protected]","address":"aa"},{"cust_id":"8","mer_id":"9","fav":"0","cont_name":"fre","kirana_name":"fee kirana","phone_no":"8698766460","email_id":"[email protected]","address":"plotno:12,sahaydri nagar"}]895da9a9a4cdd0825848479ee7e6c7ed2}
11-28 10:23:52.302 27004-27069/com.kiranaapp W/System.err: at org.json.JSONTokener.syntaxError(JSONTokener.java:450)
?どんな助けも素晴らしいでしょう。あなたより。
*を持っている必要があります...そして、いや、あなたが質問に書いたものと同じJSONではありません – Selvin
@Sidあなたがコードで投稿したJsonは、[json is invalid](http://i.imgur.com/tHJ6Gg8.png)のようにLogcatのjsonとはまったく異なります。 – Gattsu