Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/332.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/213.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在另一节课上得到截击反应_Java_Android - Fatal编程技术网

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数据格式

  • 您需要创建一个类
  • 在类中用参数字符串或数组声明一个方法,并在获得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数据格式

  • 您需要创建一个类
  • 在类中用参数字符串或数组声明一个方法,并在获得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 ;
    }
    
    
       }