【发布时间】:2017-09-14 09:06:27
【问题描述】:
从 REST API 调用 Azure 搜索,结果以类似 JSON 的结构返回。
{"@odata.context":"https://xxxx.search.windows.net/indexes('index-blob')/$metadata#docs(metadata_storage_size,metadata_storage_last_modified,metadata_storage_name,metadata_storage_path,metadata_content_type,metadata_title)","value":[{"@search.score":0.012103397,"metadata_storage_size":1479948,"metadata_storage_last_modified":"2017-04-17T18:31:18Z","metadata_storage_name":"90e975d1-3986-4167-87d2-4d1cdbc7be09.pdf","metadata_storage_path":"xxxx","metadata_content_type":"application/pdf","metadata_title":null},{"@search.score":0.004614377,"metadata_storage_size":116973,"metadata_storage_last_modified":"2017-04-13T18:24:01Z","metadata_storage_name":"xxx.pdf","metadata_storage_path":"xxxx","metadata_content_type":"application/pdf","metadata_title":"xxx"}]}
问题是我找不到真正反序列化它的方法。我无法弄清楚可以反序列化“@search.score”(或者如果查询更复杂,则使用类似参数)的结构。我尝试过使用各种 JSON->C# 转换器(包括 VS 中的 Edit->Paste Special),但没有任何效果。我不得不手动解析这些结果似乎很奇怪......我将其归因于我不了解 Azure 搜索或 JSON 的东西。
【问题讨论】:
-
你能用
JsonProperty属性解决这个问题吗? newtonsoft.com/json/help/html/… 例如。[JsonProperty("@search.score")] public float SearchScore { get; set; }- 还是我不理解你的问题? -
谢谢,完全可以接受!我在想有某种结构或 Azure 搜索参数或其他必须工作的方式。 JsonProperty 工作得很好。
标签: c# json azure azure-cognitive-search