在對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