我有一个名为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]
对我来说。我错过了什么才能获得“价值”字段?答案 0 :(得分:3)
尝试
valuesEntity[i].Resolution.Values[0].ToString();
Values
是字符串的集合。
答案 1 :(得分:0)
您也可以使用linq并执行:
valuesEntity[i].Resolution.Values.FirstOrDefault();