简体   繁体   English

使用 flutter 中的 REST api 将列表数据发送到云 Firestore 时出错

[英]Error while sending List data to cloud firestore using REST api in flutter

I'm not able to send List of string to cloud firestore using REST api in flutter.我无法使用 flutter 中的 REST api 将字符串列表发送到云 Firestore。

//###### here is my code ##########

Future<bool> addVisit(Visit visit) async { //function
try {
var response = await http.post( //post method to send data
  "${VISIT_API}",
  headers:
      {"Authorization": "Bearer ${Utils.loginToken}"},

Working fine upto "Facility", but getting error while inserting "Facility: as all others are String values and Facility is of type List在“设施”之前工作正常,但在插入“设施”时出错:因为所有其他都是字符串值,设施是列表类型

  body: json.encode(
    {
      "fields": {
        "status": {"stringValue": visit.status},
        "id": {"stringValue": visit.id},
        "name": {"stringValue": visit.name},
        "dateTime": {"integerValue": visit.dateTime},
        "mob": {"integerValue": visit.mob},
        "idproof": {"integerValue": visit.idproof},
        "address": {"stringValue": visit.address},
        "purpose ": {"stringValue": visit.purpose},
        "facility": {"arrayValue": visit.facility} //error line
      }
    },
  ),
);
print("reach");
if (response.statusCode == 200) { // successful
  print("visit added");
  return true;
} else {
  print(response.body);
}
} catch (err) {
throw err;
}
}

I do the post-request like我做事后请求

 String VISIT_API =
 "https://firestore.googleapis.com/v1/projects/<database-id>/databases/(default)/documents/visits";

Error message is here错误信息在这里

//###### Error Message #########
I/flutter (26972): {     //console output
I/flutter (26972):   "error": {
I/flutter (26972):     "code": 400,
I/flutter (26972):     "message": "Invalid JSON payload received. Unknown name \"arrayValue\" at 
'document.fields[8].value': Proto field is not repeating, cannot start list.",
I/flutter (26972):     "status": "INVALID_ARGUMENT",
I/flutter (26972):     "details": [
I/flutter (26972):       {
I/flutter (26972):         "@type": "type.googleapis.com/google.rpc.BadRequest",
I/flutter (26972):         "fieldViolations": [
I/flutter (26972):           {
I/flutter (26972):             "field": "document.fields[8].value",
I/flutter (26972):             "description": "Invalid JSON payload received. Unknown name 
\"arrayValue\" at 'document.fields[8].value': Proto field is not repeating, cannot start list."  
I/flutter (26972):           }
I/flutter (26972):         ]
I/flutter (26972):       }
I/flutter (26972):     ]
I/flutter (26972):   }
I/flutter (26972): }

//#################################

//visit.facility contains :
//["lunch" , "dinner"]

Try writing your facility array value like this:尝试像这样编写您的facility数组值:

"facility": {
  "arrayValue": {
    "values": [
      {
        "stringValue": "lunch"
      },
      {
        "stringValue": "dinner"
      }
    ]
  }
}

The "values" part comes from the references forValue and arrayValue . "values"部分来自对ValuearrayValue的引用。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 将数据插入 Cloud Firestore Flutter 时出错? - Error while Inserting data into cloud firestore flutter? 获取列表时的读取次数<documentsnapshots>在 Flutter 中使用 Cloud Firestore</documentsnapshots> - No of reads while getting List<DocumentSnapshots> in Flutter using Cloud Firestore 在颤振中从 cloud-firestore 检索数据时出错 - Error while retrieving data from cloud-firestore in flutter 使用云功能将 JSON 数据保存到 Firestore 集合时出错 - Error while saving JSON data to Firestore collection using cloud function 使用带有 Flutter Web App 的 http 包发布到 Cloud Firestore 及其 REST API - Using http package with Flutter Web App to post to Cloud Firestore and its REST API 在扑扑中使用Cloud Firestore执行搜索时出错 - error in perform searching using cloud firestore in flutter 我在尝试将数据从云 Firestore 带到我的 flutter 应用程序时遇到此错误 - I am getting this error while am trying to bring data from cloud firestore to my flutter app 使用时间戳在Cloud Firestore中列出数据 - List Data in cloud firestore using Timestamp Firebase Cloud Firestore - 通过 REST API 的身份验证错误 - Firebase Cloud Firestore - Authentication error via REST API 如何使用 function 中 flutter 中的 Firestore 云数据库中存储的数据将 NetworkImage 小部件填充/存储在列表或数组中 - How ro populate/ store NetworkImage widgets in a list or an array using the data stored in firestore cloud database in flutter in a function
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM