gpt4 book ai didi

android - 如何在android中解析没有json对象标题的json数组?

转载 作者:太空狗 更新时间:2023-10-29 15:36:29 24 4
gpt4 key购买 nike

   [
{
"name": "The Universe & The Earth"
, "imagename": "cat1.jpg"
, "active": "Y"
, "createdon": "1901-01-01"
, "lastmodifiedon": "1901-01-01 00:00:00"
, "description": "Knowledge of Earth location in the universe has been shaped by 400 years of telescopic observations, and has expanded radically in the last century.\n"
, "id": "1"
}
, {
"name": "Life on Earth"
, "imagename": "cat2.jpg"
, "active": "Y"
, "createdon": "1901-01-01"
, "lastmodifiedon": "1901-01-01 00:00:00"
, "description": "Over the last 3.7 billion years or so, living organisms on the Earth have diversified and adapted to almost every environment imaginable."
, "id": "2"
}
]

这是我的 json 值。现在我想解析并显示在自定义 ListView 中我该如何 做这个?我关注了http://www.androidhive.info/2012/01/android-json-parsing-tutorial/这是链接,但无法实现。我怎样才能做到这一点?谁能告诉我?提前致谢。

最佳答案

这是一个 JSONArray 而不是 JSONObject - 要从中创建一个 JSONObject,请使用

JSONObject jsonObject = jsonArray.getJSONObject(0);

从这个 JSONArray 获取第一个 JSONObject。

如果你有多个 JSONObjects,使用这个:

JSONObject jsonObject;
for(int n = 0; n < jsonArray.length(); n++)
{
jsonObject = jsonArray.getJSONObject(n);
}

获取值:

jsonObject.getString("name");

关于android - 如何在android中解析没有json对象标题的json数组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17613028/

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