Я использую вызов API модернизации и хочу передать JSONArray в параметрах запроса.
var requestMap: HashMap<String, Any> = hashMapOf("selected_conference_call_phone" to (getArrayOfSelectedPhones(addressItem.selectedConferenceCallPhone) as JSONArray))
private fun getArrayOfSelectedPhones(conferenceCallPhoneNumbers: ArrayList<SelectedConferenceCallNumberModel>): Any {
var phoneJsonArray = JSONArray()
try {
for (i in 0 until conferenceCallPhoneNumbers.size) {
var phoneJsonObject = JSONObject()
phoneJsonObject.put("phone", conferenceCallPhoneNumbers[i].phone)
phoneJsonArray.put(phoneJsonObject)
}
} catch (ex: Exception) {
ex.printStackTrace()
}
Timber.e("phoneNumberArray =====> $phoneJsonArray")
return phoneJsonArray
}
// api call
val request = activityApi.save(
authorization = prefs().getString(Constants.prefsKeys.TOKEN, "")
?: "", body = requestMap)
request.enqueue(object : Callback<ActivitySave> {
override fun onResponse(call: Call<ActivitySave>, response: Response<ActivitySave>) {
if (response.isSuccessful) {
hideProgress()
val activitySave = response.body()
if (activitySave != null) {
if (activitySave.flag) {
hideProgress()
greenToast(activitySave.message)
callback()
} else {
hideProgress()
Timber.e(activitySave.message)
redToast(activitySave.message)
}
}
} else {
hideProgress()
Timber.e("${response.code()}: ${response.message()}")
redToast("${response.code()}: ${response.message()}")
}
}
override fun onFailure(call: Call<ActivitySave>, throwable: Throwable) {
hideProgress()
Timber.e(throwable.message ?: "")
redToast(getString(R.string.server_unreachable))
}
})
} else {
hideProgress()
Timber.e(getString(R.string.network_not_available))
redToast(getString(R.string.network_not_available))
}
}
===========================================================
Функция дооснащения
val retrofit: Retrofit by lazy {
Retrofit.Builder()
.baseUrl(WebConstants.BASE_URL)
.client(OkHttpClient.Builder()
.connectTimeout(30, TimeUnit.SECONDS)
.readTimeout(30, TimeUnit.SECONDS)
.writeTimeout(30, TimeUnit.SECONDS)
.addInterceptor(HttpLoggingInterceptor()
.apply {
level = if (BuildConfig.DEBUG) HttpLoggingInterceptor.Level.BODY
else HttpLoggingInterceptor.Level.NONE
}).build())
.addConverterFactory(GsonConverterFactory.create())
.build()
}
================================================
использованная библиотека зависимостей:
implementation 'com.squareup.retrofit2:retrofit:2.4.0'
implementation 'com.squareup.retrofit2:converter-gson:2.4.0'
implementation 'com.squareup.retrofit2:adapter-rxjava2:2.4.0'
implementation 'com.squareup.okhttp3:logging-interceptor:3.10.0'
implementation 'com.squareup.okhttp3:okhttp:3.10.0'
, когда я проверяю запрос, он отображает
"selected_conference_call_phone": {
"values": [
{
"nameValuePairs": {
"phone": "7897897878789"
}
},
{
"nameValuePairs": {
"phone": "1234567890123"
}
}
]
}
вместо
[
{
"phone": "7897897878789"
},
{
"phone": "1234567890123"
}
]
В чем причина того, чтоэти параметры изменены?
Спасибо.