如何在Flutter中获取嵌套数据?

huangapple go评论62阅读模式
英文:

How to get data inside data in flutter?

问题

在"data"内获取"referralCode"的方法。我无法从响应中提取"referralCode"。

英文:
{"dynamic_link_data":{"data":{"referralCode":"1234"}}}

How to get referralCode inside data. I m not able to fetch referralCode from response.

答案1

得分: 1

如果您只有一个dynamic_link_data和一个data,您可以尝试以下代码:

var test = {"dynamic_link_data":{"data":{"referralCode":"1234"}}};

if (test.isNotEmpty && test.entries.first.value.isNotEmpty) {
  print(test.entries.first.value.entries.first.value['referralCode']);
}
英文:

If you have only one dynamic_link_data and also one data, you can try this:

var test = {"dynamic_link_data":{"data":{"referralCode":"1234"}}};

if (test.isNotEmpty && test.entries.first.value.isNotEmpty) {
  print(test.entries.first.value.entries.first.value['referralCode']);
}

huangapple
  • 本文由 发表于 2023年2月6日 18:13:34
  • 转载请务必保留本文链接:https://go.coder-hub.com/75359932.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定