我正在从URL解析JSON值,如果我得到null
值,那么我想要Toast
"未找到数据"
我的代码在这里
@Override
protected List<Details> doInBackground(String... params) {
List<Details> result = new ArrayList<Details>();
ServiceHandler serviceHandler=new ServiceHandler(TrainshwstnActivity.this);
String u = new String(params[0]);
String JsonStr=serviceHandler.makeServiceCall(u, ServiceHandler.GET);
Log.d("Response: ", "> " + JsonStr);
if (JsonStr != null) {
try {
JSONArray arr = new JSONArray(JsonStr);
for (int i=0; i < arr.length(); i++) {
result.add(convertContact(arr.getJSONObject(i)));
}
return result;
}
catch(Throwable t) {
t.printStackTrace();
}
return null;
}
return result;
}
答案 0 :(得分:1)
在doInbackground代码之后添加代码:
protected void onPostExecute(String result) {
if(result == null){
Toast.makeText(getApplicationContext(),"No data found", Toast.LENGTH_LONG).show();
}
}