gpt4 book ai didi

android - 在 Android Studio 中使用 GET 方法和 Volley 解析 JSON

转载 作者:行者123 更新时间:2023-11-30 01:51:32 25 4
gpt4 key购买 nike

我得到了这个 json array:

  {
"conferences": [
{
"id": 1,
"name": "Conferencia Magistral",
"description": "Conferencia bien chingona lalala",
"speaker": "Jorge",
"biography": "bioo",
"place": {
"name": "Auditorio",
"description": "Presentacion de peliculas y documentales"
},
"date": "31/10/2015",
"time": "16:00"
}
]
}

这是我在 Android Studio 中的代码:

 queue = Volley.newRequestQueue(this);

JsonArrayRequest JsonRequest = new JsonArrayRequest(Request.Method.GET, url, new Response.Listener<JSONArray>() {
@Override
public void onResponse(JSONArray response) {

try {

for (int i = 1, count = response.length(); i < count; i++) {

EventInfo eventInfo = new EventInfo();
eventInfo.name = response.getJSONObject(i).getString("name");
eventInfo.date = response.getJSONObject(i).getString("date");
eventInfo.hour_event = response.getJSONObject(i).getString("time");
eventInfo.link="http://www.tallertoa.com/v1/files/gimgs/7_botanico-lamina-21.jpg";
eventInfo.description = response.getJSONObject(i).getString("description");
eventInfos.add(eventInfo);


}
recList.setAdapter(adapter);
Log.e("JSON", response.toString());

} catch (JSONException e) {
showErrorDialog("error Json parser", "error al parsear objeto Json Evento");
Log.e("json error",e.toString());
}

}

}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {

}
});
queue.add(JsonRequest);

}

所以,我无法解析这个 Json 数组,我已经完成了,但是使用了 POST 方法,所以我想知道你们中是否有人可以告诉我如何使用 volley 来完成此操作

最佳答案

{
"conferences": [
{
"id": 1,
"name": "Conferencia Magistral",
"description": "Conferencia bien chingona lalala",
"speaker": "Jorge",
"biography": "bioo",
"place": {
"name": "Auditorio",
"description": "Presentacion de peliculas y documentales"
},
"date": "31/10/2015",
"time": "16:00"
}
]
}

首先,这是一个 JSONObject,而不是 JSONArray。你可以去herehere了解更多信息

JSONObject: ...A string beginning with { (left brace) and ending with } (right brace).

JSONArray: ...A string that begins with [ (left bracket) and ends with ] (right bracket).

因此,您可以使用 JsonObjectRequest 而不是 JsonArrayRequest

希望这对您有所帮助!

关于android - 在 Android Studio 中使用 GET 方法和 Volley 解析 JSON,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32959137/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com