【发布时间】:2018-02-28 16:14:13
【问题描述】:
下面是我的 json 输出类:
class PwdResetRequest
{
public class TopScoringIntent
{
public string intent { get; set; }
public double score { get; set; }
}
public class Intent
{
public string intent { get; set; }
public double score { get; set; }
}
public class Resolution
{
public string value { get; set; }
}
public class Entity
{
public string entity { get; set; }
public string type { get; set; }
public int startIndex { get; set; }
public int endIndex { get; set; }
public Resolution resolution { get; set; }
}
public class RootObject
{
public string query { get; set; }
public TopScoringIntent topScoringIntent { get; set; }
public List<Intent> intents { get; set; }
public List<Entity> entities { get; set; }
}
}
路易斯返回结果:
{
"query": "create a new password for sjao9841@demo.com",
"topScoringIntent": {
"intent": "ResetLANIDpassword",
"score": 0.9956063
},
"intents": [
{
"intent": "ResetLANIDpassword",
"score": 0.9956063
},
{
"intent": "None",
"score": 0.179328963
}
],
"entities": [
{
"entity": "sjao9841@demo.com",
"type": "builtin.email",
"startIndex": 26,
"endIndex": 47
}
]
}
我已经开发了以下代码来从 json 中获取数据。
var uri =
"https://westus.api.cognitive.microsoft.com/luis/v2.0/apps/" +
luisAppId + "?" + queryString;
var response = await client.GetAsync(uri);
var strResponseContent = await response.Content.ReadAsStringAsync();
var json = await response.Content.ReadAsStringAsync();
var token = JObject.Parse(json).SelectToken("entities");
foreach (var item in token)
{
var request = item.ToObject<Entity>();
}
// Display the JSON result from LUIS
Console.WriteLine(strResponseContent.ToString());
}
我只想要“TopScoringIntent”中的数据。我怎样才能使用 C# 获得它?以下是我尝试过的代码,但没有任何结果: 消息=从 JsonReader 读取 JObject 时出错。路径 '',第 0 行,第 0 位置。 Source=Newtonsoft.Json
【问题讨论】:
-
我认为代码是'above'而不是'below',否则缺少代码......
-
TopScoringIntent也不需要单独的类,它只是一个Intent -
如果你只想要来自
topScoringIntent的数据,你为什么要遍历entities? -
我正在尝试根据话语使用 luis 构建用于密码重置的 api。我需要存储 json 的值(最高得分意图到 c# 对象中)
-
你在用C#开发,为什么不用微软提供的LUIS客户端库包呢? nuget.org/packages/Microsoft.Cognitive.LUIS 您将拥有所有必要的对象来进行处理,而不是手动实现 http 调用并生成包中已经存在的类;-)
标签: c# json azure-language-understanding