我怎樣才能列出從我的 API 獲得的價格。
{
product: {
items: {
price1: {}
price2: {}
price3: {}
}
}
}
var productPrices = response.data
我試過這個來獲取價格,但我想要幫助將其轉換為串列,以便我可以將其映射到我的小部件,我在專案串列中得到的是 _JsonMap。
productPrices.forEach((key, value) {
print(key);
final Map listofItems = Map.from(value);
print(listofItems);
});
uj5u.com熱心網友回復:
通常,建議連載,但如果您愿意,可以按以下方式快速訪問產品。
(jsonDecode(data)['product']['items'] as Map).values.toList()
uj5u.com熱心網友回復:
您缺少 .items
嘗試:
productPrices.items.forEach((key, value) {
print(key);
final Map listofItems = Map.from(value);
print(listofItems);
});
uj5u.com熱心網友回復:
首先,最好為產品或您需要的模型創建一個類。您可以使用此站點從 json 生成模型。https://javiercbk.github.io/json_to_dart/
然后你可以使用 fromJson() 方法從 json 生成物件。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/535790.html
標籤:扑镖