解析 LuisResult 以获取值字段

Parsing LuisResult to get values field

我有一个名为 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"
      }
    }
  ]
}

我正在尝试访问 "resolution" 下的 "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]

对我来说。我缺少什么才能获得 "values" 字段?

尝试

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

Values是一个字符串集合。

您还可以使用 linq 并执行以下操作:

valuesEntity[i].Resolution.Values.FirstOrDefault();