微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何准确地分析抖动中的Json数据?

如何解决如何准确地分析抖动中的Json数据?

我有以下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());
      });

    }

  }

Json数据如下:

{
"movies": [
    {
      "movie_id": "youtube_cTQ3Ko9ZKg8","title": "Our planet| frozen worlds","tags": [
        "Documentary"
      ],"genres": [
        "5e10bfdf923885a2149948fd"
      ],"thumbnail": [
        "https://m.media-amazon.com/images/M/MV5BNjM3NTg0NjI5OF5BMl5BanBnXkFtZTgwNzM3NjM3NzM@._V1_SY150_CR83,101,150_.jpg"
      ],"poster_link": "https://i.ytimg.com/vi/cTQ3Ko9ZKg8/hqdefault.jpg","platform": "youtube","WORLDWIDE": 0.0,"createdAt": "2020-08-26T15:00:26.542530"
    },{
      "movie_id": "youtube_dz3uCM-MrGY","title": "Gangs Of Wasseypur 1","tags": [
        "Action","Crime","Drama","Thriller"
      ],"genres": [
        "5e10bfdc923885a2149948f7","5e10bfdf923885a2149948ff"
      ],"thumbnail": [
        "https://m.media-amazon.com/images/M/MV5BMTc5NjY4MjUwNF5BMl5BanBnXkFtZTgwODM3NzM5MzE@._V1_SY150_CR0,"poster_link": "https://i.ytimg.com/vi/dz3uCM-MrGY/hqdefault.jpg","createdAt": "2020-08-26T15:00:26.613551"
    },{
      "movie_id": "youtube_LnNcjFpILQA","title": "Andhadhun","tags": [
        "Crime","genres": [
        "5e10bfe2923885a21499490b"
      ],"thumbnail": [
        "https://m.media-amazon.com/images/M/MV5BZWZhMjhhZmYtOTIzOC00MGYzLWI1OGYtM2ZkN2IxNTI4ZWI3XkEyXkFqcGdeQXVyNDAzNDk0MTQ@.jpg"
      ],"poster_link": "https://i.ytimg.com/vi/LnNcjFpILQA/hqdefault.jpg","createdAt": "2020-08-26T15:00:25.941538"
    },

对于以上数据,当我尝试解析缩略图的数据时,我在小部件的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] .substring(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","url": "https://i.scdn.co/image/ab67706f000000022228866ad0a35846d649ef69","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,"url": "https://i.scdn.co/image/ab67706f000000025ae7aa0454c9eafdd6505fda","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,"url": "https://i.scdn.co/image/ab67706f00000002c36f26730b007e2d54e0b337","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","url": "https://i.scdn.co/image/ab67706f00000002a692c498201090e78f8c9f7e","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","url": "https://i.scdn.co/image/ab67706f0000000285046291c3f69d6e47fc77e1","playlist_followers": 2121952,"playlist_id": "37i9dQZF1DX6z20IXmBjWI"
      }
    ]
  },"publishers": [

当我尝试访问值getdata(“ music_playlists”,“ category_name”,存储数组)时,我得到的是空值

存储阵列结果为NULL

修改了getdata函数,使其仅返回一个字符串,但它也为NULL。

我探索了有关创建Podo文件以及所有其他内容方法,但是我无法真正弄清正在发生什么。

如何解决此问题?

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。