如何发送包含空格的 JSON 查询?
How to send a JSON query containing spaces?
我正在使用来自 Link
的 Volley 库填充我的 ListView
"http://192.168.***.***/allquestions/prev_ans.php/?number="+phone_number+"&&query="+query"
假设,查询 "question change" 的 Json 数组是
[{"Name":"AAAAA","Id":"101010101","ques":"question change","Type":"class1","relatedFields":"Eduation","Name":"hshsusu","ans":"new answer 1","replyDate":"2015-09-14","replyTime":"21:05:39"}]
查询 "newquestionforcrop" 的 JSON 数组是
[{"Name":"AAAAA","Id":"101010101","ques":"question change","Type":"class1","relatedFields":"Eduation","Name":"hshsusu","ans":"new answer 1","replyDate":"2015-09-14","replyTime":"21:05:39"}]
问题是,只有当我的查询之间没有 space 时,它才会填充列表。
我该如何解决?
你URL应该是编码的,因为里面不能用空格,必须用%20代替。
你应该使用类似的东西:query = URLEncoder.encode(query, "utf-8");
我正在使用来自 Link
的 Volley 库填充我的 ListView"http://192.168.***.***/allquestions/prev_ans.php/?number="+phone_number+"&&query="+query"
假设,查询 "question change" 的 Json 数组是
[{"Name":"AAAAA","Id":"101010101","ques":"question change","Type":"class1","relatedFields":"Eduation","Name":"hshsusu","ans":"new answer 1","replyDate":"2015-09-14","replyTime":"21:05:39"}]
查询 "newquestionforcrop" 的 JSON 数组是
[{"Name":"AAAAA","Id":"101010101","ques":"question change","Type":"class1","relatedFields":"Eduation","Name":"hshsusu","ans":"new answer 1","replyDate":"2015-09-14","replyTime":"21:05:39"}]
问题是,只有当我的查询之间没有 space 时,它才会填充列表。
我该如何解决?
你URL应该是编码的,因为里面不能用空格,必须用%20代替。
你应该使用类似的东西:query = URLEncoder.encode(query, "utf-8");