如何准确解析颤振中的Json数据?

如何准确解析颤振中的Json数据?,json,flutter,parsing,dart,Json,Flutter,Parsing,Dart,我有下面的Json数据(我只包含了相关的代码) 关键是我能够解析数据,但是当我使用子字符串时,它会抛出一个错误 另外,当我想解析另一个数据时,我得到的是空值,我不知道我犯了什么错误 下面是我用来解析Json数据的代码: getDataAndPutData(String objKey, String requiredKey, List<String> arrayInaction) async { String url = "https://

我有下面的Json数据(我只包含了相关的代码)

关键是我能够解析数据,但是当我使用子字符串时,它会抛出一个错误

另外,当我想解析另一个数据时,我得到的是空值,我不知道我犯了什么错误

下面是我用来解析Json数据的代码:

getDataAndPutData(String objKey, String requiredKey,
      List<String> arrayInaction) async {
    String url =
        "https://livetvapi.apyhi.com/api/v2/home?pageLocation=home&countries=IN&app_version=13&"
        "user_id=44edc2c905ae163f&package_id=livetv.movies.freemovies.watchtv.tvshows&os_platform=android";

    var res = await http
        .get(url, headers: {'Authorization': dartJsonWebTokenGenerator()});

    if (res.statusCode == 200) {
      map = json.decode(res.body);
      data = map[objKey];
      // print(data);
      _assign(requiredKey, arrayInaction);
      setState(() {
        flag1 = true;
      });
    } else {
      CircularProgressIndicator();
    }
  }


  _assign(String requiredKey, List<String> arrayInaction) {
    for (var i = 0; i < data.length; i++) {
      // youtubeHomeBannerMovieId.add(data.elementAt(i)["movie_id"]);s
      setState(() {
        arrayInaction.add(data[i][requiredKey].toString());
      });

    }

  }
对于上面的数据,当我尝试解析缩略图的数据时,我在小部件的initstate()中调用函数getDataAndPutData(“movies”、“thumbnail”、storage_array)

FadeInImage.assetNetwork(
                              width: MediaQuery
                                  .of(context)
                                  .size
                                  .width * 0.285,
                              image: storage_array[index].substring(1,storage_array.length-1),

                              placeholder: cupertinoActivityIndicator,
                              fit: BoxFit.fill,
                            ),
相关代码是storage_array[index]。子字符串(1,storage_array.length-1),……在这里我找不到子字符串。它显示了一个错误

此外,当涉及以下Json部分时:

"music_playlists": {
    "_id": null,
    "country": "IN",
    "category_id": "roots",
    "category_name": "Folk & Acoustic",
    "category_icons": [
      {
        "height": null,
        "url": "https://t.scdn.co/images/7fe0f2c9c91f45a3b6bae49d298201a4.jpeg",
        "width": null
      }
    ],
    "playlists": [
      {
        "playlist_name": "Afternoon Acoustic",
        "playlist_description": "Unwind and let the afternoon unfold in all its acoustic glory.",
        "playlist_url": "https://open.spotify.com/playlist/37i9dQZF1DX4E3UdUs7fUx",
        "playlist_total_tracks": 100,
        "playlist_images": [
          {
            "height": null,
            "url": "https://i.scdn.co/image/ab67706f000000021cb21db1932b5c9139bbf136",
            "width": null
          }
        ],
        "playlist_followers": 2422456,
        "playlist_id": "37i9dQZF1DX4E3UdUs7fUx"
      },
      {
        "playlist_name": "Acoustic Covers",
        "playlist_description": "A fun mix of folksy and acoustic covers.",
        "playlist_url": "https://open.spotify.com/playlist/37i9dQZF1DWXmlLSKkfdAk",
        "playlist_total_tracks": 100,
        "playlist_images": [
          {
            "height": null,
            "url": "https://i.scdn.co/image/ab67706f000000022228866ad0a35846d649ef69",
            "width": null
          }
        ],
        "playlist_followers": 3635732,
        "playlist_id": "37i9dQZF1DWXmlLSKkfdAk"
      },
      {
        "playlist_name": "Your Favorite Coffeehouse",
        "playlist_description": "Curl up in your favorite spot with some sweet, mellow tunes...",
        "playlist_url": "https://open.spotify.com/playlist/37i9dQZF1DX6ziVCJnEm59",
        "playlist_total_tracks": 99,
        "playlist_images": [
          {
            "height": null,
            "url": "https://i.scdn.co/image/ab67706f000000025ae7aa0454c9eafdd6505fda",
            "width": null
          }
        ],
        "playlist_followers": 3781866,
        "playlist_id": "37i9dQZF1DX6ziVCJnEm59"
      },
      {
        "playlist_name": "Run Wild",
        "playlist_description": "Uplifting and uptempo indie folk and roots rock, guaranteed to open your stride.",
        "playlist_url": "https://open.spotify.com/playlist/37i9dQZF1DX35oM5SPECmN",
        "playlist_total_tracks": 75,
        "playlist_images": [
          {
            "height": null,
            "url": "https://i.scdn.co/image/ab67706f00000002c36f26730b007e2d54e0b337",
            "width": null
          }
        ],
        "playlist_followers": 2456280,
        "playlist_id": "37i9dQZF1DX35oM5SPECmN"
      },
      {
        "playlist_name": "Relax & Unwind",
        "playlist_description": "Let your worries and cares slip away ...",
        "playlist_url": "https://open.spotify.com/playlist/37i9dQZF1DWU0ScTcjJBdj",
        "playlist_total_tracks": 100,
        "playlist_images": [
          {
            "height": null,
            "url": "https://i.scdn.co/image/ab67706f00000002a692c498201090e78f8c9f7e",
            "width": null
          }
        ],
        "playlist_followers": 3714952,
        "playlist_id": "37i9dQZF1DWU0ScTcjJBdj"
      },
      {
        "playlist_name": "Infinite Acoustic",
        "playlist_description": "Hours of your favorite acoustic and roots music gems.",
        "playlist_url": "https://open.spotify.com/playlist/37i9dQZF1DX6z20IXmBjWI",
        "playlist_total_tracks": 100,
        "playlist_images": [
          {
            "height": null,
            "url": "https://i.scdn.co/image/ab67706f0000000285046291c3f69d6e47fc77e1",
            "width": null
          }
        ],
        "playlist_followers": 2121952,
        "playlist_id": "37i9dQZF1DX6z20IXmBjWI"
      }
    ]
  },
  "publishers": [
当我尝试访问值getdata(“音乐播放列表”、“类别名称”、存储阵列)时,我的值为null

存储阵列结果为空

我修改了getdata函数,使其只返回一个字符串,但也返回NULL

我探索了创建PODO文件以及所有这些,但我无法真正弄清楚到底发生了什么


如何解决此问题?

在哪里创建数组ArrayAction?我在代码的开头声明…..添加错误片段。您正在访问空对象,或者该对象的大小大于您初始化该对象的约束ID?您没有显示该代码。@Richard Heap是的,我没有在代码中显示。我认为这很明显。我的问题您在哪里创建数组ArrayAction?我已经在代码的开头声明了……添加错误片段。您正在访问空对象,或者该对象的大小大于您初始化该对象的约束ID?你没有显示代码。@Richard Heap是的,我没有在代码中显示。我想这是显而易见的。我的错
"music_playlists": {
    "_id": null,
    "country": "IN",
    "category_id": "roots",
    "category_name": "Folk & Acoustic",
    "category_icons": [
      {
        "height": null,
        "url": "https://t.scdn.co/images/7fe0f2c9c91f45a3b6bae49d298201a4.jpeg",
        "width": null
      }
    ],
    "playlists": [
      {
        "playlist_name": "Afternoon Acoustic",
        "playlist_description": "Unwind and let the afternoon unfold in all its acoustic glory.",
        "playlist_url": "https://open.spotify.com/playlist/37i9dQZF1DX4E3UdUs7fUx",
        "playlist_total_tracks": 100,
        "playlist_images": [
          {
            "height": null,
            "url": "https://i.scdn.co/image/ab67706f000000021cb21db1932b5c9139bbf136",
            "width": null
          }
        ],
        "playlist_followers": 2422456,
        "playlist_id": "37i9dQZF1DX4E3UdUs7fUx"
      },
      {
        "playlist_name": "Acoustic Covers",
        "playlist_description": "A fun mix of folksy and acoustic covers.",
        "playlist_url": "https://open.spotify.com/playlist/37i9dQZF1DWXmlLSKkfdAk",
        "playlist_total_tracks": 100,
        "playlist_images": [
          {
            "height": null,
            "url": "https://i.scdn.co/image/ab67706f000000022228866ad0a35846d649ef69",
            "width": null
          }
        ],
        "playlist_followers": 3635732,
        "playlist_id": "37i9dQZF1DWXmlLSKkfdAk"
      },
      {
        "playlist_name": "Your Favorite Coffeehouse",
        "playlist_description": "Curl up in your favorite spot with some sweet, mellow tunes...",
        "playlist_url": "https://open.spotify.com/playlist/37i9dQZF1DX6ziVCJnEm59",
        "playlist_total_tracks": 99,
        "playlist_images": [
          {
            "height": null,
            "url": "https://i.scdn.co/image/ab67706f000000025ae7aa0454c9eafdd6505fda",
            "width": null
          }
        ],
        "playlist_followers": 3781866,
        "playlist_id": "37i9dQZF1DX6ziVCJnEm59"
      },
      {
        "playlist_name": "Run Wild",
        "playlist_description": "Uplifting and uptempo indie folk and roots rock, guaranteed to open your stride.",
        "playlist_url": "https://open.spotify.com/playlist/37i9dQZF1DX35oM5SPECmN",
        "playlist_total_tracks": 75,
        "playlist_images": [
          {
            "height": null,
            "url": "https://i.scdn.co/image/ab67706f00000002c36f26730b007e2d54e0b337",
            "width": null
          }
        ],
        "playlist_followers": 2456280,
        "playlist_id": "37i9dQZF1DX35oM5SPECmN"
      },
      {
        "playlist_name": "Relax & Unwind",
        "playlist_description": "Let your worries and cares slip away ...",
        "playlist_url": "https://open.spotify.com/playlist/37i9dQZF1DWU0ScTcjJBdj",
        "playlist_total_tracks": 100,
        "playlist_images": [
          {
            "height": null,
            "url": "https://i.scdn.co/image/ab67706f00000002a692c498201090e78f8c9f7e",
            "width": null
          }
        ],
        "playlist_followers": 3714952,
        "playlist_id": "37i9dQZF1DWU0ScTcjJBdj"
      },
      {
        "playlist_name": "Infinite Acoustic",
        "playlist_description": "Hours of your favorite acoustic and roots music gems.",
        "playlist_url": "https://open.spotify.com/playlist/37i9dQZF1DX6z20IXmBjWI",
        "playlist_total_tracks": 100,
        "playlist_images": [
          {
            "height": null,
            "url": "https://i.scdn.co/image/ab67706f0000000285046291c3f69d6e47fc77e1",
            "width": null
          }
        ],
        "playlist_followers": 2121952,
        "playlist_id": "37i9dQZF1DX6z20IXmBjWI"
      }
    ]
  },
  "publishers": [