使用Kotlin将参数放入请求截击android中
我需要用截击和科特林提出请求我的cod是使用Kotlin将参数放入请求截击android中,android,kotlin,android-volley,Android,Kotlin,Android Volley,我需要用截击和科特林提出请求我的cod是 val stringReq = StringRequest( Request.Method.GET, url, Response.Listener<String> { response -> var strResp = response.toString() val jsonObj: JSONObject = JSONObject(strResp) val jsonArray: JSON
val stringReq = StringRequest(
Request.Method.GET, url,
Response.Listener<String> { response ->
var strResp = response.toString()
val jsonObj: JSONObject = JSONObject(strResp)
val jsonArray: JSONArray = jsonObj.getJSONArray("curso")
for (i in 0 until jsonArray.length()) {
var jsonInner: JSONObject = jsonArray.getJSONObject(i)
listGeral.add(jsonInner.get("interpret").toString());
listGeral2.add(jsonInner.get("titel").toString());
listGeral3.add(jsonInner.get("id").toString());
}
},
Response.ErrorListener {
})
queue.add(stringReq)
val stringReq=StringRequest(
Request.Method.GET,url,
Response.Listener{Response->
var strResp=response.toString()
val JSONObject:JSONObject=JSONObject(strResp)
val jsonArray:jsonArray=jsonObj.getJSONArray(“curso”)
for(在0中输入i直到jsonArray.length()){
var jsonInner:JSONObject=jsonArray.getJSONObject(i)
add(jsonInner.get(“解释”).toString());
add(jsonInner.get(“titel”).toString());
添加(jsonInner.get(“id”).toString());
}
},
Response.ErrorListener{
})
queue.add(stringReq)
现在我需要为php发送3个参数。如何输入发送参数的指令?您可以在
响应后编写以下代码。ErrorListener
val sr: StringRequest = object : StringRequest(Method.POST, "url",
Response.Listener { response ->
//your response
},
Response.ErrorListener { error ->
//your error
}) {
override fun getParams(): Map<String, String> {
val params: MutableMap<String, String> = HashMap()
params["user"] = "YOUR USERNAME"
params["pass"] = "YOUR PASSWORD"
return params
}
@Throws(AuthFailureError::class)
override fun getHeaders(): Map<String, String> {
val params: MutableMap<String, String> = HashMap()
params["Content-Type"] = "application/x-www-form-urlencoded"
return params
}
}
queue.add(sr)
val sr:StringRequest=object:StringRequest(Method.POST,“url”,
Response.Listener{Response->
//你的回答
},
Response.ErrorListener{error->
//你的错误
}) {
重写fun getParams():映射{
val参数:MutableMap=HashMap()
参数[“用户”]=“您的用户名”
params[“pass”]=“您的密码”
返回参数
}
@抛出(AuthFailureError::类)
覆盖有趣的getHeaders():映射{
val参数:MutableMap=HashMap()
参数[“内容类型”]=“应用程序/x-www-form-urlencoded”
返回参数
}
}
队列添加(sr)
这已经被问到并回答了:这个响应是用JAVA编写的,我需要在KotlinJavad Dehban中查找这个错误图像现在我测试你的脚本完成了,但是当我将“for”放入(响应)应用程序崩溃时,当我放入一个获取json的循环时,应用程序在运行时崩溃