Java 在另一节课上得到截击反应
我成功地发出了第一个请求,我喜欢在其他类中访问我的截击响应,我如何才能做到这一点,因为当我尝试这样做时,它会返回一个空响应使用接口和回调Java 在另一节课上得到截击反应,java,android,Java,Android,我成功地发出了第一个请求,我喜欢在其他类中访问我的截击响应,我如何才能做到这一点,因为当我尝试这样做时,它会返回一个空响应使用接口和回调 public interface RestCallBack { void onStart(String action); void onComplete(String response, String action,Exception e); } 在你的回答中 listener.onComplete(response, action,
public interface RestCallBack {
void onStart(String action);
void onComplete(String response, String action,Exception e);
}
在你的回答中
listener.onComplete(response, action, null);
然后,您可以在需要响应的任何类中实现此接口。使用接口和回调
public interface RestCallBack {
void onStart(String action);
void onComplete(String response, String action,Exception e);
}
在你的回答中
listener.onComplete(response, action, null);
然后,您可以在需要响应的任何类中实现此接口。首先,它取决于您的json数据格式
public class MyJsonParser {
public static Vector<MyModel> getJsonResponse(Context context,String response)
throws JSONException, IOException
{
final JSONObject stringResponse = new JSONObject(response);
final JSONObject responseHolder = stringResponse.getJSONObject("data");
final JSONArray jsonArray = responseHolder .getJSONArray("arrayData");
MyModel myModel;
Vector<MyModel> myArray = new Vector<MyModel>();
for (int i= 0;i<jsonArray .length();i++){
myModel= new MyModel();
JSONObject propertyHolder = jsonArray .getJSONObject(i);
myModel.setId(propertyHolder,"id");
myModel.setName(propertyHolder, "name");
myArray .addElement(myModel);
myModel= null;
}
return myArray ;
}
}
首先,它取决于您的json数据格式
public class MyJsonParser {
public static Vector<MyModel> getJsonResponse(Context context,String response)
throws JSONException, IOException
{
final JSONObject stringResponse = new JSONObject(response);
final JSONObject responseHolder = stringResponse.getJSONObject("data");
final JSONArray jsonArray = responseHolder .getJSONArray("arrayData");
MyModel myModel;
Vector<MyModel> myArray = new Vector<MyModel>();
for (int i= 0;i<jsonArray .length();i++){
myModel= new MyModel();
JSONObject propertyHolder = jsonArray .getJSONObject(i);
myModel.setId(propertyHolder,"id");
myModel.setName(propertyHolder, "name");
myArray .addElement(myModel);
myModel= null;
}
return myArray ;
}
}