问题
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}
Here is what I tried:
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?
});
});
Any idea?
回答1:
You don't need to json.decode. The returned value is already decoded.
{key1:value1}
is the result of
final Map<String,dynamic> value = {'key1': 'value1'};
print(value.toString());
来源:https://stackoverflow.com/questions/53838388/dart-decode-json-from-a-firebase-snapshot