Value
はJSON
のKey
を返します。JSON文字列から値を取得しています
私は以下を試しましたが、どれもうまくいきませんでした。
1)
string email= json.emailAddress;
2)
string email= json["emailAddress"].ToString();
完全なコード
var api= new Uri("https://api.linkedin.com/v1/people/~:(picture-url)?format=json");
using (var webClient = new WebClient())
{
webClient.Headers.Add(HttpRequestHeader.Authorization, "Bearer " + token);
webClient.Headers.Add("x-li-format", "json");
dynamic json = webClient.DownloadString(api);
}
JSONは
{
"emailAddress": "[email protected]",
"firstName": "xxx",
"formattedName": "xxxx xxxx",
"id": "xxxxxx",
"lastName": "xxxxxx",
}
を返さ
'dynamic'を使用して良いですが、あなたはメソッドの戻り値の型を知っているときは、その型の変数を宣言する必要があり、すなわち'文字列のjson = webClient.DownloadString(API)がございます。 ' 。 'dynamic'を使うと変数の魔法の特性が得られません。もしそれが' string'ならば 'dynamic'の' string'です。 – Enigmativity