retrofit

How to parse Nested json using Retrofit …?

大憨熊 提交于 2021-02-08 03:45:28
问题 I don't know how to parse json using retrofit . Am familiar with parsing simple json using Retrofit but am not familiar with parsing nested Json using Retrofit . Here is my Json data................. { "current_observation": { "image": { "url":"http://icons.wxug.com/graphics/wu2/logo_130x80.png", "title":"Weather Underground", "link":"http://www.wunderground.com" }, { "url":"http://icons.wxug.com/graphics/wu2/logo_130x80.png", "title":"Weather Underground", "link":"http://www.wunderground.com

How can I queue up and delay retrofit requests to avoid hitting an api rate limit?

这一生的挚爱 提交于 2021-02-07 02:38:09
问题 I'm using an api that implements throttling. One of the limits is 1 request/second. ugh. I have the following scenario which hits the limit right away. Check the status of the api with api/status if the api is up, get a users subscriptions load a page from the list of subscriptions Is there anything I can plug into retrofit that can queue each network request to only run at least 1000ms after the last? I am using/learning rxjava, can debounce be of any use here? 回答1: You can throttle your

POST with Android Retrofit

谁都会走 提交于 2021-02-06 14:58:28
问题 I'm new to Android programming and working with Retrofit. I've done a bunch of research on this topic, but haven't been able to find a solution specific to my needs. I'm working with our API and trying to make a POST request. I successfully achieved this with the following non-Retrofit code: private class ProcessLogin extends AsyncTask<Void, String, JSONObject> { private ProgressDialog pDialog; String email,password; protected void onPreExecute() { super.onPreExecute(); inputEmail = (EditText

RETROFIT POST Realm object

江枫思渺然 提交于 2021-02-04 13:13:05
问题 I have the following RETROFIT API: @POST("/payments") Observable<Response> saveCreditCard(@Body CreditCard creditCard) CreditCard is a RealmObject . When I try to use my API method: CreditCard card = realm.createObject(CreditCard.class); card.setWhateverField(...); ... mApi.saveCreditCard(card) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(...); I get the following error: > retrofit.RetrofitError: com.fasterxml.jackson.databind.JsonMappingException: Realm

How to get GSON & Retrofit to serialize and map an array from a JSON response into a String?

半腔热情 提交于 2021-01-29 12:18:19
问题 I am making an API request which returns some array values. I need to serialize these array values so that I can assign them to their corresponding class attributes (which are String types). Now I know how to use GSON to serialize and deserialize lists, but with Retrofit the mapping is done automatically. This means that if my attribute is of type String, the API call returns the error "Expected a String but received an Array instead". How do I get around this so that I can receive them as

retrofit retry with the new token request?

雨燕双飞 提交于 2021-01-29 10:53:24
问题 I get new token when any request return TOKEN_IS_NOT_ACTIVE then I get a new token In interceptor override fun intercept(chain: Interceptor.Chain): Response { val request = chain.request() var response = chain.proceed(request) val bodyString = response.peekBody(AppConstants.BUFFER_SIZE_2MB)?.string() val json = JSONObject(bodyString) //after get new token retry with the failedRequest if(json.has("token"){ failedRequest=failedRequest.newBuilder().removeHeader("Authorization").removeHeader("")

list is not getting in recyclerview using retrofit

Deadly 提交于 2021-01-29 10:48:33
问题 basically im trying display list in recyclerview using retrofit and viewmodel........ on debugging the onresponse im getting 200 response but why is it not displaying list in recyclerview i dont know where im going wrong i will post up more codes if needed following is the code:--- class Tables : BaseClassActivity() { lateinit var recyclerView: RecyclerView lateinit var recyclerAdapter: TableAdapter var Tablelist : MutableList<Tabledata> = mutableListOf() override fun onCreate

Retrofit error: java.lang.NullPointerException: Attempt to invoke virtual method on a null object reference

▼魔方 西西 提交于 2021-01-29 10:13:51
问题 I am trying to create an app to allow users to register and account. I have seen this question asked a few times but i wasn't able to fix mine using the same solutions I am getting the error /AndroidRuntime: FATAL EXCEPTION: main Process: com.example.app, PID: 12181 java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String okhttp3.ResponseBody.string()' on a null object reference at com.example.app.MainActivity$1.onResponse(MainActivity.java:75) at retrofit2

Retrofit handling token expiration

纵然是瞬间 提交于 2021-01-29 10:01:20
问题 Right now im using Retrofit to fitch data from server. the problem is i need to call API to get new token every 1 hour, and so far im running background service to get new token before the 1 hour expire, and just in case if API response fail because of token expire i call the API token, than recall the method again. My question: is there's build-in way in retrofit to handle token expiration? or anything similar. 回答1: Retrofit is made to help YOU handle the requests you need. It doesn't handle

Get the result of retrofit async call

ぃ、小莉子 提交于 2021-01-29 09:04:30
问题 I tried to use retrofit to get the response data of web api, but the result of response data seems not sync as the same. fun fetchData(): LiveData<String> { val auth = Credentials.basic(name, pass) val request: Call<JsonElement> = webApi.fetchData() val response: MutableLiveData<String> = MutableLiveData() request.enqueue(object : Callback<JsonElement> { override fun onFailure(call: Call<JsonElement>, t: Throwable) { Log.e(TAG, "Failed to fetch token", t) } override fun onResponse(call: Call