【发布时间】:2017-12-27 12:23:44
【问题描述】:
我想在我的代码中使用 Volley,我不明白我应该在下面的响应中使用哪种请求类型。 网址:::http://localhost/api/product/read.php
{
"data":[
{
"category_id":"1",
"category_name":"Today's Recipe",
"recipes":[
{
"id":"1",
"recipe_name":"Peanut, and Chilli Noodles",
"ingredients":"Serves: 4 \r\n\r\n250g (9 oz) fresh Chinese ,
"prepration":"Prep:15min Cook:10min Ready in:25min \r\n\r\nCook
noodles in a large pot of boiling water until done. have
chilli paste, use minced red chilli to taste."
}
]
},
【问题讨论】:
-
这似乎是一个 JSON 对象,因此您应该使用 JsonObjectRequest developer.android.com/training/volley/request.html
-
你应该使用 JsonRequest。请参阅我在此博客上的回答:stackoverflow.com/questions/47936955/…
-
当我使用 jsonobject 请求时出现以下错误显示::: com.android.volley.ParseError: org.json.JSONException: java.lang.String 类型的值连接无法转换为 JSONObject
-
我看到最后一个逗号是这个错字还是真的是一个不完整的数组?
-
我怀疑json数据不正确。
data数组未关闭,我猜"prepration"是ingredients属性的一部分。仅供参考,您的 localhost 网址仅适用于您而不是我们,因为服务器已部署在您的系统中。