在对api进行查询后,我得到一个json响应。解析C#中的JSON响应#
的JSON是这样的:
{
"results": [
{
"alternatives": [
{
"confidence": 0.965,
"transcript": "how do I raise the self esteem of a child in his academic achievement at the same time "
}
],
"final": true
},
{
"alternatives": [
{
"confidence": 0.919,
"transcript": "it's not me out of ten years of pseudo teaching and helped me realize "
}
],
"final": true
},
{
"alternatives": [
{
"confidence": 0.687,
"transcript": "is so powerful that it can turn bad morals the good you can turn awful practice and the powerful once they can teams men and transform them into angel "
}
],
"final": true
},
{
"alternatives": [
{
"confidence": 0.278,
"transcript": "you know if not on purpose Arteaga Williams who got in my mother "
}
],
"final": true
},
{
"alternatives": [
{
"confidence": 0.621,
"transcript": "for what pink you very much "
}
],
"final": true
}
],
"result_index": 0
}
我必须做两件事情上面JSON结果(我把它作为一个字符串*):
- 获取的成绩单部(S) JSON响应。
处理这些字符串。
- 我对此很陌生。转换为字符串只能称为序列化。为什么反序列化会在这里起作用?
转换为字符串:我做到了使用:
var reader = new StreamReader(response.GetResponseStream());
responseFromServer = reader.ReadToEnd();
如何实现这一目标?
有没有需要反序列化 - 但它会让你的生活更轻松:o) –
反序列化JSON将它转换回.NET对象。然后,您可以访问该对象的属性,而不是进行一堆字符串解析。使用像Newtonsoft JSON.NET这样的库来帮助反序列化。 – wablab