2016-04-19 8 views

Antwort

2

Benutzeroberfläche zurückkehren und Rückruf

public interface RestCallBack { 

    void onStart(String action); 

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

und in Ihrem onResponse

listener.onComplete(response, action, null); 

Dann können Sie diese Schnittstelle in jeder Klasse implementieren, wo Sie die Antwort wollen.

0

zunächst seine auf json Datenformat hängt .......

  1. Sie brauchen eine Klasse
  2. Deklarieren Sie eine Methode in der Klasse mit einem Parameter-String oder Array zu erstellen und rufen Sie diese Verfahren, in dem Sie erhalten json Antwort

oder diesen Code

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 ; 
} 


    } 

und rufen folgen t seine Methode, wo Sie JSON Antwort wie folgt bekommen ....

MyJsonParser.getJsonResponse(context,response); 
Verwandte Themen