Dart: decode Json from a Firebase snapshot

空扰寡人 提交于 2020-08-11 04:27:18

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!