【发布时间】:2021-04-03 15:18:15
【问题描述】:
如何获取嵌套对象值? print(_user.userLocation()['location']); 返回{country: Eesti, city: Tallin}
所以,我尝试使用_user.userLocation()['location']['city'] 来获取值Tallinn。但是,我得到了
The operator '[]' isn't defined for the type 'Object'. Try defining the operator '[]'.
print(_user.userLocation()) 和 print(_user.location().runtimeType); 返回
location: {
country: Eesti,
city: Tallinn,
}
flutter: _InternalLinkedHashMap<String, dynamic>
我尝试将变量设置为var a = _user.location()['location'],然后设置为a['city']。但是,这并不奏效。
【问题讨论】:
-
请检查我添加的答案