Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/firebase/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/flutter/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何从firebase颤振获取fieldValue.arrayUnion数据_Firebase_Flutter_Dart_Google Cloud Firestore - Fatal编程技术网

如何从firebase颤振获取fieldValue.arrayUnion数据

如何从firebase颤振获取fieldValue.arrayUnion数据,firebase,flutter,dart,google-cloud-firestore,Firebase,Flutter,Dart,Google Cloud Firestore,我已经要求提供fieldunion阵列的数据 Future _getData(String email) async { await FirebaseFirestore.instance .collection("shop") .get() .then((querySnapshot) { querySnapshot.docs.forEach((result) {

我已经要求提供fieldunion阵列的数据

Future _getData(String email) async {
        await FirebaseFirestore.instance
            .collection("shop")
            .get()
            .then((querySnapshot) {
          querySnapshot.docs.forEach((result) {
            print(result.data()["products"]);
          });
        });
      }
这是我得到的数据,是产品的fieldunion阵列

[{img:[https://firebasestorage.googleapis.com/v0/b/geniemart-387b1.appspot.com/o/seller%2Fproduct%2Frohanchoudhary2000%40gmail.com%2F20%2Fimage_1?alt=media&token=6b67a55d-01aa-4970-b518-719c30db7938,https://firebasestorage.googleapis.com/v0/b/geniemart-387b1.appspot.com/o/seller%2Fproduct%2Frohanchoudhary2000%40gmail.com%2F20%2Fimage_2?alt=media&token=483b46e0-9d8f-48ec-b431-d083341d4815,https://firebasestorage.googleapis.com/v0/b/geniemart-387b1.appspot.com/o/seller%2Fproduct%2Frohanchoudhary2000%40gmail.com%2F20%2Fimage_3?alt=media&token=fea76365-59cd-47d2-96a4-55a9387dfbf5,https://firebasestorage.googleapis.com/v0/b/geniemart-387b1.appspot.com/o/seller%2Fproduct%2Frohanchoudhary2000%40gmail、 com%2F20%2Fimage_4?alt=media&token=a2136333-d099-4465-8121-2cf9f2e75d61],价格:123,频率:[],折扣:12,销售人:制造商,寿命:72.0,寿命:5年,制造商:制造商,isveg:true,操作:123,名称:tgbbb,id:10000000,类别:番茄,品牌:tgbbb,lat:28.0,desc:gyyhh}

现在,我想特别得到它的一个属性category的值,怎么做?
result.data()

[ERROR:flutter/lib/ui/ui_dart_state.cc(177)] Unhandled Exception: RangeError (index): Invalid value: Not in inclusive range 0..1: 2

如果不使用jsonDecode方法将其转换为列表,请确保执行result.data()[“products”]时返回的数据类型为List 以便允许您访问该列表的字段

现在,在确定了上述事项之后

因此,如果它是字符串,请尝试以下操作:

动态结果=jsonDecode(result.data()[“products”]); 字符串类别=结果[0][“类别”]

如果它已经是一个列表,您可以直接访问您的类别字段,如下所示:
result.data()[“products”][0][“category”]

在执行result.data()[“products”]时,请确保返回的数据类型为List,如果不使用jsonDecode方法将其转换为List 以便允许您访问该列表的字段

现在,在确定了上述事项之后

因此,如果它是字符串,请尝试以下操作:

动态结果=jsonDecode(result.data()[“products”]); 字符串类别=结果[0][“类别”]

如果它已经是一个列表,您可以直接访问您的类别字段,如下所示: result.data()[“产品”][0][“类别”]