解析值时遇到意外字符:e。路径“”,第 0 行,位置 0,同时尝试删除 documentDB 中的文档
Unexpected character encountered while parsing value: e. Path '', line 0, position 0 while trying to delete documents in documentDB
我有一个字符串作为 documentDB 的 ID,它很长。
var longId = "Ardell Natural Lashes are popular lashes because women love that they're lightweight, reusable, easy-to-apply and give the desired, natural look of full, beautiful lashes. \n• Ardell false eyelashes are made from sterilized, 100% human hair."
var documentlink = database + "/doc/" + longId;
当我想删除文档时,我需要从 ID 创建的文档 link。当我执行那个函数时,我收到了这个异常消息
"Unexpected character encountered while parsing value: e. Path '', line 0, position 0 while trying to delete documents in documentDB."
谁能建议我如何将该字符串更改为在 documentDB 中可用的字符串?
这里有几个问题:
为了在字符串中使用'\n',您需要将其转义为'\n',以便JSON 正确序列化它。执行此操作后,您将从 DocumentDB 收到一条有意义的消息:"The resource name presented contains invalid character '\'"。
我们不允许“\”作为 Id 的一部分,因此您必须从字符串中删除“\n”才能使其正常工作。
语句中:var documentlink = database + "/doc/" + longId;
我不确定 "database" 解析为什么,但它应该解析为类似 "dbs/your_db_id/colls/your_coll_id" 的内容 您缺少“/doc/”中的 's',因此需要将其更改为“/docs/” ”。
为了避免创建 documentLink 的所有这些问题,C# SDK 有一个 UriFactory static class,您可以按如下方式使用它来获取可以传递给 DeleteDocumentAsync 方法的 documentLink(Uri 格式)。这是它的样子:
Uri documentUri = UriFactory.CreateDocumentUri(database, collection, longId);
其中 database 是数据库的 id,collection 是您的文档集合的 id。
希望对您有所帮助!
此致,
拉杰什
我有一个字符串作为 documentDB 的 ID,它很长。
var longId = "Ardell Natural Lashes are popular lashes because women love that they're lightweight, reusable, easy-to-apply and give the desired, natural look of full, beautiful lashes. \n• Ardell false eyelashes are made from sterilized, 100% human hair."
var documentlink = database + "/doc/" + longId;
当我想删除文档时,我需要从 ID 创建的文档 link。当我执行那个函数时,我收到了这个异常消息
"Unexpected character encountered while parsing value: e. Path '', line 0, position 0 while trying to delete documents in documentDB."
谁能建议我如何将该字符串更改为在 documentDB 中可用的字符串?
这里有几个问题:
为了在字符串中使用'\n',您需要将其转义为'\n',以便JSON 正确序列化它。执行此操作后,您将从 DocumentDB 收到一条有意义的消息:"The resource name presented contains invalid character '\'"。 我们不允许“\”作为 Id 的一部分,因此您必须从字符串中删除“\n”才能使其正常工作。
语句中:var documentlink = database + "/doc/" + longId; 我不确定 "database" 解析为什么,但它应该解析为类似 "dbs/your_db_id/colls/your_coll_id" 的内容 您缺少“/doc/”中的 's',因此需要将其更改为“/docs/” ”。 为了避免创建 documentLink 的所有这些问题,C# SDK 有一个 UriFactory static class,您可以按如下方式使用它来获取可以传递给 DeleteDocumentAsync 方法的 documentLink(Uri 格式)。这是它的样子: Uri documentUri = UriFactory.CreateDocumentUri(database, collection, longId);
其中 database 是数据库的 id,collection 是您的文档集合的 id。
希望对您有所帮助!
此致, 拉杰什