2016-04-19 8 views

答えて

2

使用インタフェースを返すことをことを行うことができますどのように、他のクラスの私のバレーボール応答にアクセスしたいですコールバック

public interface RestCallBack { 

    void onStart(String action); 

    void onComplete(String response, String action,Exception e); 
} 

そして、あなたのonResponseで

listener.onComplete(response, action, null); 

次に、あなたが応答をしたい任意のクラスでは、このインタフェースを実装することができます。

0

最初はそのあなたのJSONデータメートに依存.......

  1. あなたはパラメータの文字列や配列を使ってクラスのメソッドを宣言し、これを呼び出すクラス
  2. を作成する必要がありますあなたは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 ; 
} 


    } 

とtを呼び出すに従うを取得する方法このようなjsonレスポンスを得る方法...

MyJsonParser.getJsonResponse(context,response); 
関連する問題