gpt4 book ai didi

java - Android - 如何使用索引处的对象解析 json

转载 作者:太空宇宙 更新时间:2023-11-03 11:44:16 25 4
gpt4 key购买 nike

<分区>

我是初学者,所以我不知道如何解析json,当json数据没有key时

这是我的Json数据

[
{
"products_id":10052,
"products_name":"\u0e08\u0e35\u0e19 : The Haven Sword and Dragon Sabre - \u0e01\u0e23\u0e30\u0e1a\u0e35\u0e48\u0e1f\u0e49\u0e32\u0e14\u0e32\u0e1a\u0e21\u0e31\u0e07\u0e01\u0e23 1994 **\u0e1a\u0e32\u0e07\u0e15\u0e2d\u0e19\u0e2d\u0e32\u0e08\u0e44\u0e21\u0e48\u0e15\u0e48\u0e2d\u0e40\u0e19\u0e37\u0e48\u0e2d\u0e07\u0e15\u0e49\u0e2d\u0e07\u0e02\u0e2d\u0e2d\u0e20\u0e31\u0e22**",
"products_description":"<P>\u0e19\u0e31\u0e01\u0e41\u0e2a\u0e14\u0e07:<BR>- \u0e2b\u0e21\u0e48\u0e32\u0e08\u0e34\u0e48\u0e07\u0e40\u0e17\u0e32 (Steven Ma Jing Tao) \u0e23\u0e31\u0e1a\u0e1a\u0e17 \u0e40\u0e15\u0e35\u0e22\u0e1a\u0e48\u0e2d\u0e01\u0e35\u0e49 \u0e01\u0e31\u0e1a...",
"products_date_available":"0",
"products_image":"100909-TheHavenSword.jpg",
"addDate":"2010-10-24 09:59:58"
},
{
"products_id":10117,
"products_name":"Nogizaka Haruka no Himitsu - \u0e04\u0e27\u0e32\u0e21\u0e25\u0e31\u0e1a\u0e02\u0e2d\u0e07\u0e22\u0e31\u0e22\u0e04\u0e38\u0e13\u0e2b\u0e19\u0e39 Season 1 + 2 (\u0e1a\u0e23\u0e23\u0e22\u0e32\u0e22\u0e44\u0e17\u0e22) **\u0e02\u0e2d\u0e2d\u0e20\u0e31\u0e22\u0e1a\u0e32\u0e07\u0e15\u0e2d\u0e19\u0e20\u0e32\u0e1e\u0e44\u0e21\u0e48\u0e15\u0e23\u0e07\u0e01\u0e31\u0e1a\u0e40\u0e2a\u0e35\u0e22\u0e07\u0e40\u0e19\u0e37\u0e48\u0e2d\u0e07\u0e08\u0e32\u0e01\u0e15\u0e49\u0e19\u0e09\u0e1a\u0e31\u0e1a**",
"products_description":"<P>Nogizaka Haruka \u0e19\u0e32\u0e07\u0e40\u0e2d\u0e01\u0e02\u0e2d\u0e07\u0e40\u0e23\u0e37\u0e48\u0e2d\u0e07\u0e19\u0e35\u0e49 \u0e40\u0e1b\u0e47\u0e19\u0e44\u0e2d\u0e14\u0e2d\u0e25\u0e2b\u0e19\u0e36\u0e48\u0e07\u0e40\u0e14\u0e35\u0e22\u0e27\u0e02\u0e2d\u0e07\u0e42\u0e23\u0e07\u0e40\u0e23\u0e35\u0e22\u0e19\u0e19\u0e35...",
"products_date_available":"0",
"products_image":"10-NogizakaHarukaNoHimitsu.jpg",
"addDate":"2010-09-30 10:20:03"
}

我无法循环此 Json,因为没有方法调用 .getJSONArray("key") 的键

这是我的Java

JSONObject object = new JSONObject(resultValue);

//JSONArray jsonArray = object.getJSONArray("key");
for (int i = 0; i < jsonArray.length(); i++){
JSONObject objJson = jsonArray.getJSONObject(i);
int products_id = objJson.getInt("products_id");
String products_name = objJson.getString("products_name");
Toast.makeText(getApplicationContext(),products_name,Toast.LENGTH_SHORT).show();

}

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