Microsoft Cognitive Services Web搜索API-反序列化问题

亚什维尔·辛格(Yashveer singh)

我想学习Cognitive Services Web搜索API,因此开始创建bot应用程序。我已经有一个帐户子密钥和其他必需的信息,我也阅读了许多文章,还观看了有关此版本的2016年视频。在反序列化结果时遇到了麻烦。我找不到可以用来做的代理类。我使用的网址是https://api.cognitive.microsoft.com/bing/v5.0/search/,我发现了以前api版本的代理类。谁能告诉我如何在VS 2015中为这些服务获取api请求/响应的代理类。

我的代码如下所示:

  string BingSearchUrl =  "https://api.cognitive.microsoft.com/bing/v5.0/search/";
   const string bingKey = "Key";

    public static  async Task<string> Search(string query)
    {
        var client = HttpClientFactory.Create();
        var queryString = BingSearchUrl + "?q=" + query + "&count=10";        
        // Request headers
        client.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", bingKey);
        client.DefaultRequestHeaders.Add("Accept", "application/json");

        // Request parameters
        string r = await client.GetStringAsync(queryString);
        var jsonResult = JsonConvert.DeserializeObject<Bing.ExpandableSearchResult>(r);

        return jsonResult.Web.First().Title;
亚什维尔·辛格(Yashveer singh)

有了这个模型,我就能得到想要的结果。在我的情况下,另一个答案中提出的模型不起作用。

namespace BingSearchBot
{
    public class RootObject
    {
        public string _type { get; set; }
        public WebPages webPages { get; set; }
        public RelatedSearches relatedSearches { get; set; }
        public RankingResponse rankingResponse { get; set; }
    }
    public class WebPages
    {
        public string webSearchUrl { get; set; }
        public int totalEstimatedMatches { get; set; }
        public List<Value> value { get; set; }
    }
    public class Value
    {
        public string id { get; set; }
        public string name { get; set; }
        public string url { get; set; }
        public List<About> about { get; set; }
        public string displayUrl { get; set; }
        public string snippet { get; set; }
        public List<DeepLink> deepLinks { get; set; }
        public string dateLastCrawled { get; set; }
        public List<SearchTag> searchTags { get; set; }
    }
    public class About
    {
        public string name { get; set; }
    }

    public class DeepLink
    {
        public string name { get; set; }
        public string url { get; set; }
        public string snippet { get; set; }
    }

    public class SearchTag
    {
        public string name { get; set; }
        public string content { get; set; }
    }
    public class Value2
    {
        public string text { get; set; }
        public string displayText { get; set; }
        public string webSearchUrl { get; set; }
    }

    public class RelatedSearches
    {
        public string id { get; set; }
        public List<Value2> value { get; set; }
    }

    public class Value3
    {
        public string id { get; set; }
    }

    public class Item
    {
        public string answerType { get; set; }
        public int resultIndex { get; set; }
        public Value3 value { get; set; }
    }

    public class Mainline
    {
        public List<Item> items { get; set; }
    }

    public class RankingResponse
    {
        public Mainline mainline { get; set; }
    }
}

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

Microsoft Cognitive Services Web搜索API-反序列化问题

来自分类Dev

Microsoft Cognitive Services Face API-获取上传的图像

来自分类Dev

Microsoft Cognitive Services Vision API:发送多部分数据

来自分类Dev

是否存在Microsoft Cognitive Services图像搜索API-V5的Rails宝石?

来自分类Dev

Microsoft Cognitive Service Web搜索API以XML格式输出

来自分类Dev

将 Microsoft Cognitive Services Emotion API 用于 Android 中的本地视频

来自分类Dev

Microsoft Cognitive API的正确密钥

来自分类Dev

Microsoft Cognitive Services JavaScript请求“访问控制允许来源”

来自分类Dev

Microsoft Cognitive Services Face API-如何在没有可可豆的情况下集成iOS框架?

来自分类Dev

对Web API的PUT请求的JSON反序列化问题

来自分类Dev

从Web API反序列化JSON

来自分类Dev

web api的反序列化

来自分类Dev

将带有中文字符的XML发布到Microsoft Translator API会引发反序列化异常

来自分类Dev

反序列化 Web Json

来自分类Dev

反序列化API响应

来自分类Dev

从API反序列化嵌套的json

来自分类Dev

在C#UWP中从RIOT Api反序列化Json的问题

来自分类Dev

Microsoft Cognitive Auth令牌到期

来自分类Dev

从Web Api反序列化自定义异常

来自分类Dev

从Web API反序列化XML数组

来自分类Dev

从ASP Web Api IHttpActionResult反序列化byte []

来自分类Dev

Web Api错误地反序列化枚举列表

来自分类Dev

C#反序列化JSON Web API响应

来自分类Dev

Web Api错误地反序列化枚举列表

来自分类Dev

反序列化弹性搜索json数据

来自分类Dev

针对Microsoft Cognitive API使用Invoke-RestMethod获取400错误的请求错误

来自分类Dev

针对Microsoft Cognitive API使用Invoke-RestMethod获取400错误的请求错误

来自分类Dev

Microsoft Cognitive Face API-如何从Kinect的视频源中获取人脸属性?

来自分类Dev

ASMX Web服务的反序列化部分失败

Related 相关文章

  1. 1

    Microsoft Cognitive Services Web搜索API-反序列化问题

  2. 2

    Microsoft Cognitive Services Face API-获取上传的图像

  3. 3

    Microsoft Cognitive Services Vision API:发送多部分数据

  4. 4

    是否存在Microsoft Cognitive Services图像搜索API-V5的Rails宝石?

  5. 5

    Microsoft Cognitive Service Web搜索API以XML格式输出

  6. 6

    将 Microsoft Cognitive Services Emotion API 用于 Android 中的本地视频

  7. 7

    Microsoft Cognitive API的正确密钥

  8. 8

    Microsoft Cognitive Services JavaScript请求“访问控制允许来源”

  9. 9

    Microsoft Cognitive Services Face API-如何在没有可可豆的情况下集成iOS框架?

  10. 10

    对Web API的PUT请求的JSON反序列化问题

  11. 11

    从Web API反序列化JSON

  12. 12

    web api的反序列化

  13. 13

    将带有中文字符的XML发布到Microsoft Translator API会引发反序列化异常

  14. 14

    反序列化 Web Json

  15. 15

    反序列化API响应

  16. 16

    从API反序列化嵌套的json

  17. 17

    在C#UWP中从RIOT Api反序列化Json的问题

  18. 18

    Microsoft Cognitive Auth令牌到期

  19. 19

    从Web Api反序列化自定义异常

  20. 20

    从Web API反序列化XML数组

  21. 21

    从ASP Web Api IHttpActionResult反序列化byte []

  22. 22

    Web Api错误地反序列化枚举列表

  23. 23

    C#反序列化JSON Web API响应

  24. 24

    Web Api错误地反序列化枚举列表

  25. 25

    反序列化弹性搜索json数据

  26. 26

    针对Microsoft Cognitive API使用Invoke-RestMethod获取400错误的请求错误

  27. 27

    针对Microsoft Cognitive API使用Invoke-RestMethod获取400错误的请求错误

  28. 28

    Microsoft Cognitive Face API-如何从Kinect的视频源中获取人脸属性?

  29. 29

    ASMX Web服务的反序列化部分失败

热门标签

归档