Sto cercando di scaricare una stringa JSON in mio Windows App Store, che dovrebbe assomigliare a questo:scaricare una stringa JSON in C#
{
"status": "okay",
"result": {"id":"1",
"type":"monument",
"description":"The Spire",
"latitude":"53.34978",
"longitude":"-6.260316",
"private": "{\"tag\":\"david\"}"}
}
ma sto ottenendo quello che sembra informazioni relative al server. L'uscita sto ottenendo è il seguente:
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
}
Ho cercato in giro e vedo che WebClient è stato utilizzato prima di Windows 8, ed è ora sostituito con HttpClient. Quindi, invece di usare DownloadString(), sto usando Content.ReadAsString(). Ecco il bit di codice che ho finora:
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();
}
Qualcuno sa dove sto andando male? Grazie in anticipo!
Poiché non stai utilizzando la risposta per nient'altro. Perché non usi semplicemente ['HttpClient.GetStringAsync'] (http://msdn.microsoft.com/en-us/library/hh551746.aspx)? – khellang