解析LuisResult以获取值字段

问题描述 投票:1回答:2

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

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

    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]

对我来说。我错过了什么才能获得“价值”字段?

c# botframework luis
2个回答
3
投票

尝试

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

Values是一系列字符串。


0
投票

您也可以使用linq并执行:

valuesEntity[i].Resolution.Values.FirstOrDefault();
© www.soinside.com 2019 - 2024. All rights reserved.