retrofit2

Retrofit 2, same name different data type JSON Parsing

杀马特。学长 韩版系。学妹 提交于 2019-12-20 02:33:05
问题 I am trying to parse a JSON response from a server, If there are changes to in the query sent in post method I will get first one as response, if not I will get the second one as response. 1: { "status": 1, "data": { "firstname": "First Name", "lastname": "Last Name", "mobilenumber": "1234567894", "emailid": "test@gmail.com", "timezone": "Asia/Kolkata" }, "user_id": "", "response": "Profile Updated Successfully" } 2: { "status": 1, "data": "No changes to update", "user_id": "" } As you can

Runtime Execption java.lang.NoClassDefFoundError: retrofit2.Platform in Android

孤街浪徒 提交于 2019-12-19 08:29:34
问题 i am using Rtofit to handling the Serverside Data from Mobile After Implementing the Retrofit I am Getting the below Exception any know about this issue tell me where i am did wrong Init Retrofit: mRetrofit = new Retrofit.Builder() .baseUrl(AppConstance.APP_URL) .addConverterFactory(GsonConverterFactory.create()) .build(); Iservice = mRetrofit.create(IdeaService.class); Gradle File dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) testCompile 'junit:junit:4.12' compile 'com

Unit Test of Retrofit 2 api call with Mockito

丶灬走出姿态 提交于 2019-12-19 06:43:50
问题 I need some advices on how to mock a rest api. My application is in MVP architecture. My interface for API: public interface MyAPI { @GET("{cmd}/{userName}/{password}") Observable<Response> login( @Path("cmd") String cmd, @Path("userName") String userName, @Path("password") String password ); My service: public class MyService implements IService { private static MyService mInstance = new MyService(); private MyAPI mApi; public static MyService getInstance() { return mInstance; } private

Unit Test of Retrofit 2 api call with Mockito

删除回忆录丶 提交于 2019-12-19 06:41:36
问题 I need some advices on how to mock a rest api. My application is in MVP architecture. My interface for API: public interface MyAPI { @GET("{cmd}/{userName}/{password}") Observable<Response> login( @Path("cmd") String cmd, @Path("userName") String userName, @Path("password") String password ); My service: public class MyService implements IService { private static MyService mInstance = new MyService(); private MyAPI mApi; public static MyService getInstance() { return mInstance; } private

How to send Form data in retrofit2 android

旧巷老猫 提交于 2019-12-18 19:17:18
问题 Hi i have a json to send to the server (POST METHORD) {"country":"india","devicetype":"android"} it is in form data model like the key for this json is data ie is the server accept it like data={"country":"india","devicetype":"android"} am using retrofit i use Multipart like this @Multipart @POST("initiate") @Headers({ "Content-Type: application/json", "Cache-Control: no-cache" }) Call<UserInfoServerResponse> getUserInfoRequest(@Part(value="data") UserInfo mUserInfo); here UserInfo is the

How to fetch JSON array without any key in Retrofit (Android)?

别等时光非礼了梦想. 提交于 2019-12-18 16:52:05
问题 I have a JSON array without any object(key) inside which there are JSON Objects like this : [ { "Type": "Meeting", "Name": "TestMeeting", "StartDate": "2016-03-22T08:00:00", "EndDate": "2016-03-24T09:00:00" } ] I tried to parse it but can't find success,Can anyone suggest me how to parse this type of Response using Retrofit ? 回答1: You Can define a Class representing the JSON Object import com.google.gson.annotations.Expose; import com.google.gson.annotations.SerializedName; public class

Get html of a website with retrofit - Android?

ぐ巨炮叔叔 提交于 2019-12-18 16:51:41
问题 How can I get html of a website with retrofit ? for example I have this url and I need to get html of this url and how can I load more . Bellow is my code : MainActivity.java: public class MainActivity extends AppCompatActivity { TextView txt; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); txt = (TextView) findViewById(R.id.txt); OkHttpClient okHttpClient = new OkHttpClient().newBuilder() .build();

How to fetch JSON array without any key in Retrofit (Android)?

不想你离开。 提交于 2019-12-18 16:50:10
问题 I have a JSON array without any object(key) inside which there are JSON Objects like this : [ { "Type": "Meeting", "Name": "TestMeeting", "StartDate": "2016-03-22T08:00:00", "EndDate": "2016-03-24T09:00:00" } ] I tried to parse it but can't find success,Can anyone suggest me how to parse this type of Response using Retrofit ? 回答1: You Can define a Class representing the JSON Object import com.google.gson.annotations.Expose; import com.google.gson.annotations.SerializedName; public class

How can I return value from onResponse of Retrofit v2

别等时光非礼了梦想. 提交于 2019-12-18 13:37:41
问题 I want to return a string value from my function. But I do not know how to handle it? I tried final one-array solution but it did not work out. Here is my code: public String revealCourtPlace(String courtID) { BaseService.getInstance().getUniqueCourt(Session.getToken(),courtID).enqueue(new Callback<JsonObject>() { @Override public void onResponse(Call<JsonObject> call, Response<JsonObject> response) { JsonObject object = response.body(); boolean success = object.get("success").getAsBoolean();

How to pass string in 'Body' Parameter of Retrofit 2 in android

放肆的年华 提交于 2019-12-18 13:00:34
问题 @POST("api/login") Call<ApiResponse> loginUser(@Body String user); Here the string is actually a JSONstring i.e. {"email":"test@gmail.com","password":"test"} Couldnt figure out what is wrong in this. Either the string it again converted to json. Please suggest.. This is what i want to do to my request as shown in picture. 回答1: Convert your data in object public class Credentials { public String email; public String password; } Set the data to object Credentials loginCredentials = new