Dart:从Firebase快照中解码Json [英] Dart: decode Json from a Firebase snapshot
本文介绍了Dart:从Firebase快照中解码Json的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这可能是一个琐碎的问题,我尝试从Firebase快照中解码json,这是json的结构:
it's probably a trivial question, I try to decode a json from a Firebase snapshot, here is the structure of the json :
firebaseKey1 : {img1:value1}
firebaseKey2 : {img2:value2}
firebaseKey3 : {img3:value3}
这是我尝试的方法:
DatabaseReference firebaseRef = FirebaseDatabase.instance.reference();
firebaseRef.child('...').once().then((DataSnapshot snapshot) {
Map<dynamic,dynamic> map = snapshot.value;
map.forEach((key, jsonString) {
print('$key: $jsonString'); // jsonString = {img1:value1}
//how to get value1 inside jsonString?
});
});
有什么主意吗?
推荐答案
您不需要json.decode
.返回值已被解码.
You don't need to json.decode
. The returned value is already decoded.
{key1:value1}
是
final Map<String,dynamic> value = {'key1': 'value1'};
print(value.toString());
这篇关于Dart:从Firebase快照中解码Json的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文