如何从HttpClient解析JSON字符串?
如何从HttpClient解析JSON字符串?
通过调用外部API,我得到了一个JSON结果。
HttpClient client = new HttpClient(); client.BaseAddress = new Uri(url); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); HttpResponseMessage response = client.GetAsync(url).Result; if (response.IsSuccessStatusCode) { var result = response.Content.ReadAsStringAsync().Result; var s = Newtonsoft.Json.JsonConvert.DeserializeObject(result); return "Success"; } else { return "Fail"; }
在代码行`var s = Newtonsoft.Json.JsonConvert.DeserializeObject(result);`中,我得到的结果如下:
{
"query": "1",
"topScoringIntent": {
"intent": "1",
"score": 0.9978111,
"actions": [
{
"triggered": false,
"name": "1",
"parameters": []
}
]
},
"entities": [],
"dialog": {
"prompt": "1",
"parameterName": "1",
"parameterType": "1::1",
"contextId": "11",
"status": "1"
}
}
我正在使用`HttpClient`。我在访问`dialog`中的`prompt`键值时遇到了困难。我想要获取`dialog`中的`prompt`值。我该如何获取?