c# - 解析 LuisResult 以获取值字段

标签 c# botframework azure-language-understanding

我有一个名为 result 的 LuisResult 变量,它具有类似

的 JSON 信息
{
  "query": "what is twenty * three",
  "topScoringIntent": {
    "intent": "Multiplication",
    "score": 0.740870655
  },
  "intents": [
    {
      "intent": "Multiplication",
      "score": 0.740870655
    },
    {
      "intent": "Subtraction",
      "score": 0.04339512
    },
    {
      "intent": "None",
      "score": 0.0164503977
    },
    {
      "intent": "addition",
      "score": 0.0126439808
    },
    {
      "intent": "Division",
      "score": 0.0108866822
    }
  ],
  "entities": [
    {
      "entity": "twenty",
      "type": "builtin.number",
      "startIndex": 8,
      "endIndex": 13,
      "resolution": {
        "value": "20"
      }
    },
    {
      "entity": "three",
      "type": "builtin.number",
      "startIndex": 17,
      "endIndex": 21,
      "resolution": {
        "value": "3"
      }
    }
  ]
}

我正在尝试访问“分辨率”下的“值”字段,因为它将数字的字符串表示形式转换为数字表示形式。目前我只是想获得第一个值。我试过用这种方式提取值(value)

    var valuesEntity = result.Entities;               //IList of all entities
    string s = "";
    s = valuesEntity[i].Resolution.Values.ToString(); //extract value field??
    await context.PostAsync($"{s}");                  //post to emulator

这会打印出 System.Collections.Generic.Dictionary`2+ValueCollection[System.String,System.String]

给我。我缺少什么才能获得“值”字段?

最佳答案

尝试

valuesEntity[i].Resolution.Values[0].ToString();

Values 是字符串的集合。

关于c# - 解析 LuisResult 以获取值字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42984395/

相关文章:

azure-language-understanding - 短语列表中的 "The values are interchangable"选项如何在 LUIS 中工作?

c# - 在C#中生成日期

c# - UDP打洞实现

c# - 来自 C# 的 javascript unicode 属性

json - 微软团队 : "Something went wrong" while installing my custom app into my organization's team

azure - 如何写入日志流服务

botframework - 使用机器人框架创建谷歌助手应用程序

c# - 如果 POST 请求中的文件总大小超过 30MB,ASP.NET Core 将抛出 -4077 ECONNRESET

botframework - Luis 可以用于在 MSFT Bot Framework 以外的平台上设计的机器人吗

java - 是否可以使用 API 创建聊天机器人模型,将意图、对话从 Java 传递到 AZURE 机器人服务