I'm just getting started messing around with the SO api,SO API. I haven't worked with JSON before, and I am getting a strange result from a basic call (No API Key).
WebClient stackClient = new WebClient();
string result = stackClient.DownloadString(@"http://api.stackoverflow.com/0.8/stats");
The result is:
‹í½
I–%&/mÊ{JõJ×àt¡€
$Ø@ìÁˆÍæ’ìiG#)«*ÊeVe]f@Ìí¼÷Þ{ï½÷Þ{ï½÷º;N'÷ßÿ?\fdlöÎJÚÉž!€ªÈ?~|?"~ñoœ¤éGM›µEÓÓæ£Gé÷ðQšþbùA߶U›•¿ÿ/ZçÔ¢Z¢É§Ÿ~ºs0ê´X/³es•×ùŒšìîܸ{¯ÛDÄîýýƒûûÝÓj±È—-Zì=ع·ói¯—˪͇vwwöº_O²Ù…|ÿpÿþnþº‘î÷öïïݻᄉ£ûýWyýû/ŠåºÍ©ÙÎøÁ×H±›ìŽ?õî{@¼ž²Uñû_ꌾ³T¦oܧíŒ>²¯ÐWu~Y˜ïvÇ;ãݽ{ûãûŸ>8øÈ4ú%ò ÿøþoœü’äÿNïþìÚ
I'm not sure what sort of formatting I'm missing, but this looks like I'm missing something obvious, it just isn't obvious to me.
Any thoughts?
Edited to add a bit of code to decompress the API data:
WebClient stackClient = new WebClient();
byte[] compressedData = stackClient.DownloadData(@"http://api.stackoverflow.com/0.8/stats");
int messageLength = BitConverter.ToInt32(compressedData, 0);
using (MemoryStream ms = new MemoryStream(compressedData,0,compressedData.Length))
{
byte[] decompressedData = new byte[messageLength];
using (GZipStream gZip = new GZipStream(ms, CompressionMode.Decompress))
{
gZip.Read(decompressedData, 0, decompressedData.Length);
}
string result = Encoding.UTF8.GetString(decompressedData);
}