【问题标题】:Text property not serialized文本属性未序列化
【发布时间】:2017-07-24 13:23:33
【问题描述】:

我正在尝试从 Azure 函数中将以下文档写入 DocumentDb:

dynamic doc = new {
    customer = "mycust",
    version = "version2",
    document = JObject.Parse("{\"prop1\": \"Some text.\"}")
}

await 
_client.CreateDocumentAsync(UriFactory.CreateDocumentCollectionUri("db", "coll"),doc);

当保存到 documentdb 时,我得到:

{
  "customer": "mycust",
  "version": "version2",
  "document": {
    "prop1": []
  },
  "id": "93ccb6d6-8829-4179-beba-606078f63dea"
}

“某些文字”丢失。在调试器中它被正确解析。

【问题讨论】:

    标签: azure azure-functions azure-cosmosdb


    【解决方案1】:

    根据您的描述,我检查了这个问题,并通过以下方法进行了测试,您可以参考:

    #r "Newtonsoft.Json"
    using System.Net;
    using System;
    using Newtonsoft.Json;
    using Newtonsoft.Json.Linq;
    
    public static HttpResponseMessage Run(HttpRequestMessage req,out object outputDocument,TraceWriter log)
    {
        dynamic doc = new
        {
           customer = "mycust",
           version = "version2",
           document = JObject.Parse("{\"prop1\": \"Some text.\"}")
        };
        outputDocument=doc;
        return req.CreateResponse(HttpStatusCode.OK, "success");
    }
    

    或者参考Azure WebJobs SDK Extensions for DocumentDB进行如下配置:

    #r "Newtonsoft.Json"
    using System.Net;
    using System;
    using Newtonsoft.Json;
    using Newtonsoft.Json.Linq;
    using Microsoft.Azure.WebJobs.Extensions.DocumentDB;
    
    public static HttpResponseMessage Run(HttpRequestMessage req,[DocumentDB("brucedb-2", "todoitem",ConnectionStringSetting = "brucedocumentdb-01_DOCUMENTDB")] out object outputDocument,TraceWriter log)
    {
        dynamic doc = new
        {
            customer = "mycust",
            version = "version2",
            document = JObject.Parse("{\"prop1\": \"Some text.\"}")
        };
        outputDocument=doc;
        return req.CreateResponse(HttpStatusCode.OK, "success");
    }
    

    此外,您还可以利用 Microsoft Azure DocumentDB Client Library 并参考此类似的 issue 将新文档添加到 Azure DocumentDB。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-04-01
      • 2012-12-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-10-05
      • 2015-10-23
      • 1970-01-01
      相关资源
      最近更新 更多