Unparseable StackExchange API response
Ich habe ein kleines Programm geschrieben, um meine Profildaten über die StackExchange-API zu analysieren, aber die API gibt mir nicht lesbare Daten zurück.
Daten erhalten (selbst heruntergeladen mit c #)
\ u001f \ b \ 0 \ 0 \ 0 \ 0 \ 0 \ u0004 \ 0mRMo 0 \ f /: d $ c '˱ ^ {/ \ u0006 \ u0018G > \ I D> GR L' o \ u0004G JP% JP \ u001c - Em> 0 X bm ~ (DLG v0 ~ Fj = 1 31 kTRA "(/ +. +; Nl h P藄 藄X aL w # 3 \ u0002 + \ u007f \ u0010 \ u000f p ] v \ u007f \ t \ nf u \ u0018 \ u0014eƺ _ƺ 1x # j ^ - c AX \ t \ u0014 \ "\ a ^ \ b # \ u00e QG % y \ t q00K \ av \ u0011 {ظ \ u0005 \ "\ u001d + | \ u007f ' \ u0016 ~ 8 \ u007f \ u0001-h ] O \ u007fV o \ u007f \ u0001 ~ Y \ u0003 \ u0002 \ 0 \ 0
Daten gesucht: (von meinem Browser kopiert)
{"items": [{"badge_counts", {"bronze": 987, "silver": 654, "gold": 321}, "account_id": 123456789, "is_employee": false, "last_modified_date": 1250612752, "last_access_date": 1250540770, "age": 0, "reputationswechsel_jahr": 987, "reputationswechsel_quartal": 654, "reputationswechsel_monat": 321, "reputationswechsel_woche": 98, "reputationswechsel_tag": 76, "reputationswechsel": 9876, "creation_date" ": 1109670518," user_type ":" registered "," user_id ": 123456789," accept_rate ": 0," location ":" Australia "," website_url ":"http: //example.or","Verknüpfung":"http: //example.org/usernam","Profilbild":"http: //example.org/username/icon.pn "," display_name ":" username "}]," has_more ": false," quota_max ": 300," quota_remaining ": 300}
Ich habe diese (Erweiterungs-) Methode geschrieben, um einen String aus dem Internet herunterzuladen:
public static string DownloadString(this string link)
{
WebClient wc = null;
string s = null;
try
{
wc = new WebClient();
wc.Encoding = Encoding.UTF8;
s = wc.DownloadString(link);
return s;
}
catch (Exception)
{
throw;
}
finally
{
if (wc != null)
{
wc.Dispose();
}
}
return null;
}
Ich habe dann im Internet nach einer Methode zum Herunterladen von Zeichenfolgen gesucht und dabei eine andere Taktik angewendet:
public string DownloadString2(string link)
{
WebClient client = new WebClient();
client.Encoding = Encoding.UTF8;
Stream data = client.OpenRead(link);
StreamReader reader = new StreamReader(data);
string s = reader.ReadToEnd();
data.Close();
reader.Close();
return s;
}
Aber beide Methoden geben dieselben (ungelesenen / nicht analysierbaren) Daten zurück.
Wie kann ich lesbare Daten von der API erhalten? Fehlt etwas?