【发布时间】:2018-12-18 03:44:58
【问题描述】:
为什么我不能在 url 中发送参数,字符串在 JSON 对象请求中包含多个单词?
当我尝试使用字符串“haha”发送参数时,它可以工作,但是当我尝试使用字符串“haha haha”(单词之间有空格)发送参数时,它会调用 onErrorResponse 函数。
下面是我的代码:
String url = String.format("http://172.xx.x.xx:xxxxx/api/users?name=%s", nama);
JsonObjectRequest objectRequest = new JsonObjectRequest(
Request.Method.GET,
url,
null,
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
}
});
有什么办法让我的url可以接收字符串参数中包含多个单词的字符串参数??
【问题讨论】:
-
请尝试像
new URLEncoder().encode(nama, Charsets.UTF_8)一样编码nama。
标签: java android json jsonobjectrequest