如何使用 C# 从 LUIS 返回的 JSON 结果中仅获取 "intent" 字段

How to get only "intent" field from LUIS returned JSON result using C#

如何从 C# 中的 LUIS return 结果中的 JSON 格式代码中仅获取 "intent" 字段? 我已经像这样进行了反序列化:

public class ResponseContent
{
    [BsonId]
    public string query { get; set; }
    public string topScoringIntent { get; set; }
    public string intent { get; set; }
    public string entities { get; set; }
}

public class topScoringIntent
{
    public string intent { get; set; }
    public string score { get; set; }
}

这是 LUIS return 结果:

"query": "Hello.",
"topScoringIntent": 
{
"intent": "Greeting",
"score": 0.9447609
},
"intents": 
[
{
  "intent": "Greeting",
  "score": 0.9447609
},
{
  "intent": "Request",
  "score": 0.09726282
},
{
  "intent": "None",
  "score": 5.523394E-10
}
],
"entities": []

我只想要 "TopScoringIntent" 中的 "intent" 字段。我如何使用 C# 获得它?下面是我试过但没有结果的代码:

var uri = "https://southeastasia.api.cognitive.microsoft.com/luis/v2.0/apps/" + luisAppId + "?" + queryString;
var response = await client.GetAsync(uri);
var responseContent = await response.Content.ReadAsStringAsync();
var responseitem = JsonConvert.SerializeObject(responseContent,Formatting.Indented);
JToken content = JToken.Parse(responseitem);
var intentOnly = (from s in content.Children()["ResponseContent"]select s).ToList();
foreach (var item in intentOnly.Children().ToList())
{
  Console.WriteLine(item.ToObject<ResponseContent>().TopScoringIntent);
}

这不是机器人,所以我没有使用任何机器人框架来执行此操作。 谢谢。

使用以下代码完成:

var jsonresponse = JObject.Parse(responseContent);
intentonly = jsonresponse.SelectToken("intents[0].intent").ToString();