2016-06-05 23 views
1

Ich bin neu im Retrofit. Ich habe alle Einstellungen abgeschlossen. ich diesen gradle in build.gradle Datei hinzufügenJson Object Request mit Retrofit2

compile 'com.squareup.retrofit2:retrofit:2.0.2' 
    compile 'com.squareup.retrofit2:converter-gson:2.0.2' 

Meine Schnittstelle ist wie folgt:

ILoginInterface.Factory.getInstance().startLogin(jsonObject).enqueue(new Callback<LoginResponseEntity>() { 
       @Override 
       public void onResponse(Call<LoginResponseEntity> call, retrofit2.Response<LoginResponseEntity> response) { 
        Log.d("MS",response.body().fullName); 
       } 

       @Override 
       public void onFailure(Call<LoginResponseEntity> call, Throwable t) { 
        Log.d("MS",t.getMessage()); 
       } 
      }); 

Hier jsonObject ist wie folgt:

public interface ILoginInterface { 
    String BASE_URL= "MY_BASE_URL/"; 

    @POST("MY/API") 
    Call<LoginResponseEntity> startLogin(@Body JSONObject jsonObject); 

    class Factory{ 
     private static ILoginInterface instance; 

     public static ILoginInterface getInstance(){ 
      if(instance==null){ 
       Retrofit retrofit = new Retrofit.Builder() 
         .baseUrl(BASE_URL) 
         .addConverterFactory(GsonConverterFactory.create()) 
         .build(); 

       instance = retrofit.create(ILoginInterface.class); 
      } 

      return instance; 
     } 

    } 
} 

Meine Berufung Verfahren ist wie folgt:

{"user_name":"sajedul Karim", "password":"123456"} 

Hier scheint alles in Ordnung zu sein, aber ich habe keine richtige Antwort bekommen. Ich habe eine Lösung gefunden. es ist here. Hat jemand die richtige Lösung haben wie Volley JsonObjectRequest

+0

Ich verstehe nicht, wonach Sie fragen. – nasch

Antwort

1

Mai werden Sie importieren

import org.json.JSONObject; 

sollten Sie

import com.google.gson.JsonObject; 

Dann werden Sie es Wert ist.

+1

Ja, das ist der genaue Punkt. Es ist mein Problem zu lösen. –