質問

WP7アプリでSO APIからの結果を取得しようとしています。次のコードを使用したときにコンソールアプリで機能することができました。

static void webClient_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
        {
            Console.Clear();
            DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(RootObject));
            var stream = new MemoryStream(Encoding.Default.GetBytes(e.Result));
            var gzstream = new GZipInputStream(stream);

            RootObject qs = ser.ReadObject(gzstream) as RootObject;

            foreach (Question q in qs.questions)
            {
                Console.WriteLine(q.title);
            }

        }
.

重要な部分はエンコードされていました。私がError Gzipヘッダーで戻ってきて、最初のマジックバイトが一致しないか、似たものにも似ていないことがありません。

wp7はデフォルトではなく、どちらも機能しないUnicodeとUTF8のみです。

アイデア?

役に立ちましたか?

解決 2

use WebRequest.BeginGetResponse instead. This way you can get the bytes as @carlosfigueria suggested but since webclient only has getstring this is a work around.

他のヒント

Don't use WebClient.DownloadString, use DownloadData. This way you'll receive the GZip-encoded bytes (which can't really be converted to string), and you can pass it directly to the GZupInputStream.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top