我正在构建销售点应用程序,因此无法在json数组中发送多个json对象。我的应用程序从android数据库(SQLite)中读取,并将多个产品发送到服务器。有人帮我吗?谢谢
Logcat: E / Volley:[893] BasicNetwork.performRequest:https://…的意外响应代码422
override fun getHeaders(): MutableMap<String, String> {
val headers = HashMap<String, String>()
headers["Accept"] = "application/json"
headers["Content-Type"] = "application/x-www-form-urlencoded"
headers["Authorization"] = "Bearer " + user_info.token
return headers
}
override fun getParams(): MutableMap<String,String> {
val cartRepository = CartRespository(application)
val transaksi = cartRepository.getByIdTrans(id_trans)
val jo = JSONObject()
val ja = JSONArray()
for(i in 0 until transaksi.size){
ja.put(i,jo.put("product_id", transaksi[i].id_item))
ja.put(i,jo.put("jumlah", transaksi[i].kuantitas).toString())
}
val map = HashMap<String, String>()
map.put("rfid", "122312")
map.put("device", user_info.device)
map.put("products", ja.toString())
return map
}
这是我的请求API正文,通常在邮递员中运行。
{ “ rfid”:“ 122312”, “ device”:“ 1233311”, “产品”:[ { “ product_id”:4 “ jumlah”:“ 1” } ] }