gpt4 book ai didi

java - Android Studio 解析 JSON 对象不起作用

转载 作者:行者123 更新时间:2023-12-01 17:29:39 24 4
gpt4 key购买 nike

这是我的 json 文件。我正在尝试将 json 加载到我的 recyclerview 中,但在尝试从 body 对象获取数组后,它运行时出错。

{
body: {
posters: [
{
code: "3292d2r",
attributes: [
"12-plus-trailer",
"2d",
"adventure",
"dubbed",
"dubbed-lang-hu",
"fantasy"
],
featureTitle: "Artemis Fowl",
weight: 0,
dateStarted: "2020-05-28T00:00:00"

我的java代码:

public void onResponse(String response) {
progressDialog.dismiss();

try {
JSONObject jsonObject=new JSONObject(response);
JSONArray jsonArray=jsonObject.getJSONArray("body");

但是这个方法不起作用,知道如何将海报中的项目获取到 JSONARRAY 吗?JSON文件结构:

{
body: {
posters: [
{},
{},
{},
{},
{},
{},
{},
{},
{},
{},
{},
{},
{},
{}
]
}
}

最佳答案

body 不是 JSONArray。它是一个 JSONObject。

jsonObject.getJSONObject("body").getJSONArray("posters");

关于java - Android Studio 解析 JSON 对象不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61146281/

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