C#でJSON文字列をダウンロード:は、私は次のようになります。これは私のWindowsストアアプリの中でJSON文字列をダウンロードしようとしている
{
"status": "okay",
"result": {"id":"1",
"type":"monument",
"description":"The Spire",
"latitude":"53.34978",
"longitude":"-6.260316",
"private": "{\"tag\":\"david\"}"}
}
が、私は、サーバーに関する情報どのように見えるかを取得しています。私の周り見て、Webクライアントは、Windows 8の前に使用され、現在のHttpClientに置き換えられていることを確認してきた
Response: StatusCode: 200, ReasonPhrase: 'OK', Version: 1.1, Content: System.Net.Http.StreamContent, Headers:
{
MS-Author-Via: DAV
Keep-Alive: timeout=15, max=100
Connection: Keep-Alive
Date: Thu, 22 Nov 2012 15:13:53 GMT
Server: Apache/2.2.22
Server: (Unix)
Server: DAV/2
Server: PHP/5.3.15
Server: with
Server: Suhosin-Patch
Server: mod_ssl/2.2.22
Server: OpenSSL/0.9.8r
X-Powered-By: PHP/5.3.15
Content-Length: 159
Content-Type: text/json
}
次のように私は取得しています出力されます。だから、DownloadString()を使う代わりに、私はContent.ReadAsString()を使っています。ここに私がこれまで持っているコードのビットがあります:
public async Task<string> GetjsonStream()
{
HttpClient client = new HttpClient();
string url = "http://(urlHere)";
HttpResponseMessage response = await client.GetAsync(url);
Debug.WriteLine("Response: " + response);
return await response.Content.ReadAsStringAsync();
}
どこが間違っているのですか? ありがとうございます!
あなたは何も応答しません。なぜあなたは['HttpClient.GetStringAsync'](http://msdn.microsoft.com/en-us/library/hh551746.aspx)を使ってみませんか? – khellang