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の結果に2つのことを実行する必要があります。
- トランスクリプト部分(複数可)のを取得します。 jsonの応答。
これらの文字列を処理します。
- これは初めてのことです。文字列に変換することは、シリアライゼーションと呼ばれます。デシリアライゼーションはなぜここで助けになるのですか?
文字列に変換する:
var reader = new StreamReader(response.GetResponseStream());
responseFromServer = reader.ReadToEnd();
はどのようにこれを達成するために:私は使用してそれをやりましたか?
デシリアライズの必要はありませんが、それはあなたの人生を楽にします:o) –
JSONを逆シリアル化して.NETオブジェクトに変換し直します。その後、文字列の解析を行うのではなく、そのオブジェクトのプロパティにアクセスすることができます。デシリアライズを支援するために、Newtonsoft JSON.NETのようなライブラリを使用してください。 – wablab