英文:
how to extract a json data using flutter
问题
在我的Flutter应用中,我有一个JSON对象的列表。我使用这些对象来获取其他数据。返回类型是 Map<int, List<int>>
,对象结构如下:
{1:[1,7], 2:[1,141]}
{2:[142, 252]}
{2:[253, 286], 3:[1,92]}
...
这是它的返回内容。第一个数字表示章节,数组表示节的起始和结束。所以我想要做的是分别获取章节名称、节的起始和结束。
那么,如何遍历这些数据呢?
英文:
In my fluter app i have a list of json object. and with this object i use it to fetch other datas.the return type is Map<int, List<int>>
, and the object structure is as follows.
{1:[1,7], 2:[1,141]}
{2:[142, 252]}
{2:[253, 286], 3:[1,92]}
...
this is what it returns. the first number indicates the chapter, the arrays are the verse start and end. so what i wanted todo with this is to get the chapter names, the verse start and end, separately.
so how can i map through this data?
答案1
得分: 1
最简单的方法是遍历data
。
输出:
Chapter 1 verse [1, 7]
Chapter 2 verse [1, 141]
Chapter 2 verse [142, 252]
Chapter 2 verse [253, 286]
Chapter 3 verse [1, 92]
英文:
The simplest answer would be iterating through the data
.
List<Map<int, List<int>>> data = [
{1:[1,7], 2:[1,141]},
{2:[142, 252]},
{2:[253, 286], 3:[1,92]}
];
for (var item in data) {
item.forEach((key, value) {
print('Chapter $key verse $value');
});
}
Output:
Chapter 1 verse [1, 7]
Chapter 2 verse [1, 141]
Chapter 2 verse [142, 252]
Chapter 2 verse [253, 286]
Chapter 3 verse [1, 92]
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论