Java 如果我已经将循环中的所有字符串存储到向量类中,如何停止onPostExecute()方法的执行?
在Java 如果我已经将循环中的所有字符串存储到向量类中,如何停止onPostExecute()方法的执行?,java,android,android-asynctask,android-json,Java,Android,Android Asynctask,Android Json,在杂志.java上,我实现了asynctask的onPostExecute()方法,我读过一些教程,在我的例子中,asynctask的onPostExecute()方法将继续,即使我已经从doInBackground()方法中得到了结果,在我的onPostExecute()方法中有一个循环,我想从doInBackGround()方法的结果中获取JSONArray的每个JSONObject,将其转换为字符串,并将每个JSONObject存储到一个向量: @Override public void
杂志.java
上,我实现了asynctask的onPostExecute()
方法,我读过一些教程,在我的例子中,asynctask的onPostExecute()
方法将继续,即使我已经从doInBackground()
方法中得到了结果,在我的onPostExecute()
方法中有一个循环,我想从doInBackGround()
方法的结果中获取JSONArray的每个JSONObject,将其转换为字符串,并将每个JSONObject
存储到一个向量:
@Override
public void onPostExecute(String result) {
try{
JSONObject jsonRootObj = new JSONObject(result);
JSONArray jsonArray = jsonRootObj.optJSONArray("Data");
int pagenumber = jsonArray.length();
for (int x = 0; x<=pagenumber; x++){
String jsonObjStr = jsonArray.getJSONObject(x).toString();
jsonObjStr = "{ \n \"Data\": \n " + jsonObjStr + " \n }";
objs.addElement(jsonObjStr);
}
mag_samp.setText(objs.elementAt(0));
//just to check if the vector objs has a content, I called the very first element but it doenst return anything
} catch(JSONException e){
}
}
@覆盖
public void onPostExecute(字符串结果){
试一试{
JSONObject jsonRootObj=新的JSONObject(结果);
JSONArray JSONArray=jsonRootObj.optJSONArray(“数据”);
int pagenumber=jsonArray.length();
for(int x=0;xonPostExecute()
仅在doInBackground()
被查找后才被调用。我认为您将onPostExecute()
与onProgressUpdate()
混淆了。请参阅您使用的@John Ranniel Sinel(int x=0;x请查看您的日志猫,并检查它是否显示任何JSONEXCEPTION。它已经好了,感谢您的帮助,我想我只是在循环结构方面遇到了一些问题:)OnPropostExecute将只在doInBackground完成is执行后调用一次。请再次调用文档,我相信您将能够在回调之间完美地分发代码。