【问题标题】:flutter merging two or more JSON data and using them as one in list view or future builder颤动合并两个或多个 JSON 数据并将它们用作列表视图或未来构建器中的一个
【发布时间】:2022-01-08 10:13:55
【问题描述】:

我一直在我的 Flutter 应用程序中处理 JSON 文件,我想将多个 JSON 数据合并到一个 Listview.builderFutureBuilder 中。就我而言,我有一个音频 JSON 文件和文本 JSON 文件。

var data;

Future<void> getAll() async{

     // text JSON
    final url1 = "http://api.alquran.cloud/v1/quran/en.asad";
    Uri myUri1 = Uri.parse(url1);
    final response1 = await http.get(myUri1);

     //audio JSON
    final url2 = "http://api.alquran.cloud/v1/quran/ar.alafasy";
    Uri myUri2 = Uri.parse(url2);
    final response2 = await http.get(myUri2);
    
    /* here I want to combine 
    response = response1 + response2
    then add it to data as */

    if (response.statusCode == 200) {
        data = json.decode(response.body.toString());
    } else {
       throw Exception('Failed to load text');
    }
  }

那么我该如何组合这些呢?如果我可以添加两个,我该如何处理更多 JSON 数据?

【问题讨论】:

    标签: json flutter dart


    【解决方案1】:

    实际上我找到了答案。我只是这样使用它。

    data = json.decode(response1.body.toString());
          data.addAll(json.decode(response2.body.toString()));
    

    我还没有尝试过更多 JSON 数据,但它适用于两个 JSON 文件。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-12-21
      • 1970-01-01
      • 1970-01-01
      • 2011-06-03
      相关资源
      最近更新 更多