私は結果を持つjsonオブジェクトを返す非同期タスクを呼び出しています。メッセージは文字列として、結果はコストです。文字列のJson例外の取得
結果を表示しますが、レスポンスオブジェクトのメッセージ文字列には、json例外がresultの値として表示されません。
Asynctask
public class SearchPostsAsyncTask extends AsyncTask<String, Void, JSONObject> {
String api;
JSONObject jsonParams;
Context mContext;
private SearchPostsCallBack searchPostsCallBack;
private ProgressDialog loadingDialog;
private Snackbar snackbar;
private LinearLayout parentLayout;
private ArrayList<PostDelivery> list;
private JSONArray listsArray;
private JSONObject jsonObject;
public SearchPostsAsyncTask(Context context, LinearLayout linearLayout,SearchPostsCallBack searchPostsCallBack) {
this.mContext = context;
this.searchPostsCallBack = searchPostsCallBack;
this.parentLayout = linearLayout;
}
public interface SearchPostsCallBack {
void doPostExecute(ArrayList<PostDelivery> list);
}
@Override
protected void onPreExecute() {
super.onPreExecute();
loadingDialog = new ProgressDialog(mContext);
if (!isOnline()) {
snackbar = Snackbar.make(parentLayout, R.string.check_network, Snackbar.LENGTH_LONG);
snackbar.show();
} else {
loadingDialog.show(mContext, null,mContext.getString(R.string.wait));
}
}
@Override
protected JSONObject doInBackground(String... params) {
try {
api = mContext.getResources().getString(R.string.url) + "requestlist";
jsonParams = new JSONObject();
jsonParams.put("st_lati", params[0]);
jsonParams.put("st_longi", params[1]);
jsonParams.put("ed_lati", params[2]);
jsonParams.put("ed_longi", params[3]);
jsonParams.put("pt_date", params[4]);
ServerRequest request = new ServerRequest(api, jsonParams);
return request.sendPostRequest(params[5]);
} catch (JSONException je) {
Log.e("exception",je.toString());
return Excpetion2JSON.getJSON(je);
} catch (Exception ue) {
return Excpetion2JSON.getJSON(ue);
}
}
@Override
protected void onPostExecute(JSONObject response) {
super.onPostExecute(response);
if (loadingDialog.isShowing())
loadingDialog.dismiss();
try {
list = new ArrayList<>();
String result = response.getString("result");
String message = response.getString("message");
if (result.equals("1")) {
listsArray = response.getJSONArray("cost");
for (int j = 0; j < listsArray.length(); j++) {
jsonObject = listsArray.getJSONObject(j);
PostDelivery postDelivery = new PostDelivery();
postDelivery.setmPt_id(jsonObject.getString("pt_id"));
postDelivery.setmPt_name(jsonObject.getString("pt_name"));
postDelivery.setmPtDetail(jsonObject.getString("pt_detail"));
postDelivery.setmPtStartLoc(jsonObject.getString("pt_start_loc"));
postDelivery.setmPtEndLoc(jsonObject.getString("pt_end_loc"));
postDelivery.setmPtDate(jsonObject.getString("pt_date"));
list.add(postDelivery);
searchPostsCallBack.doPostExecute(list);
}
}
snackbar = Snackbar.make(parentLayout, "sorry", Snackbar.LENGTH_LONG);
snackbar.show();
}catch (JSONException je) {
je.printStackTrace();
// Toast.makeText(getApplicationContext(), je.getMessage(), Toast.LENGTH_LONG).show();
}
}
}
例外と応答が:
D/ServerResponse: {"result":1,"message":"Success","cost":[{"pt_id":"5","ur_id":"2","pt_name":"mobile","pt_detail":"samsung mobile ","pt_size":"0","pt_weight":"150","pt_start_loc":"nashik"}]}
06-04 19:26:06.284 7129-7129/com.carryapp W/System.err: org.json.JSONException: No value for result
は間違ってここで何が起こっていますか?助けてください。ありがとうございます。
結果は、整数.see、無ダブルクォートです! – Pzy64