解析值时遇到意外的字符:e。(Unexpected character encountered while parsing value: e. Path '', line 0, p

编程入门 行业动态 更新时间:2024-10-26 10:39:47
解析值时遇到意外的字符:e。(Unexpected character encountered while parsing value: e. Path '', line 0, position 0 while trying to delete documents in documentDB)

我有一个字符串作为documentDB的ID,这个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创建的文档链接。 当我执行该函数时,我收到了此异常消息

"Unexpected character encountered while parsing value: e. Path '', line 0, position 0 while trying to delete documents in documentDB."

任何人都可以告诉我如何将该字符串更改为documentDB中可用的字符串?

I have a string as an ID for documentDB which is pretty long.

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;

When I want to delete the document I need the document link which is created from ID. When I execute that function, I got this exception message

"Unexpected character encountered while parsing value: e. Path '', line 0, position 0 while trying to delete documents in documentDB."

Can anyone suggest me how to change that string to be a usable one in documentDB?

最满意答案

这里有几个问题:

为了在字符串中使用'\ n',您需要像'\ n'一样转义它,以便JSON正确地序列化它。 完成后,您将从DocumentDB收到一条有意义的消息:“显示的资源名称包含无效字符'\'”。 我们不允许'\'作为Id的一部分,因此您必须从字符串中删除'\ n'才能使其正常工作。

在声明中:var documentlink = database +“/ doc /”+ longId; 我不确定什么“数据库”可以解决,但它应该解决类似于“dbs / your_db_id / colls / your_coll_id”您从\“/ doc /”中缺少's',因此需要将其更改为“/ docs / ”。 为了避免创建documentLink时出现所有这些问题,C#SDK有一个UriFactory静态类,您可以按如下方式使用它来获取可以传递到DeleteDocumentAsync方法的documentLink(以Uri格式)。 它是这样的:Uri documentUri = UriFactory.CreateDocumentUri(database,collection,longId);

其中数据库是数据库的标识,集合是文档集合的标识。

希望有所帮助!

问候,Rajesh

There are couple of issues here:

In order to use '\n' in a string, you need to escape it like '\n', in order for JSON to serialize it properly. Once you do that you will get a meaningful message from DocumentDB: "The resource name presented contains invalid character '\'". We don't allow '\' as part of the Id, so you would have to get rid of the '\n' from your string to make it work.

In the statement: var documentlink = database + "/doc/" + longId; I'm not sure what "database" resolves to but it should resolve to something like "dbs/your_db_id/colls/your_coll_id" You are missing 's' from "/doc/" so this needs to be changed to "/docs/". In order to avoid all these issues for creating the documentLink, C# SDK has a UriFactory static class that you can use as follows to get the documentLink(in Uri format) that you can pass onto DeleteDocumentAsync method. Here is how it looks like: Uri documentUri = UriFactory.CreateDocumentUri(database, collection, longId);

where database is the id of the database and collection is the id of your document collection.

Hope that helps!

Regards, Rajesh

更多推荐

本文发布于:2023-08-02 04:09:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1368528.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:字符   意外   character   encountered   parsing

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!