简体   繁体   English

在Windows Phone 7中使用json webservice

[英]consuming json webservice in windows phone 7

I am making a windows phone app which can consume json from this link http://dir.yummly.com/4/public/8a753a70358c827b01358da787bd68f3 , however when i try to download data asynchronously , i am unable to get e.result in a readable language. 我正在制作一个Windows手机应用程序,可以从这个链接http://dir.yummly.com/4/public/8a753a70358c827b01358da787bd68f3消耗json,但是当我尝试异步下载数据时,我无法获得可读的e.result语言。 here is my c# code -- 这是我的c#代码 -

    Uri sub4 = new Uri("http://dir.yummly.com/4/public/8a753a70358c827b01358da787bd68f3");
        string kit = sub4.ToString();
    WebClient w = new WebClient();
        w.DownloadStringCompleted += new DownloadStringCompletedEventHandler(wc_DownloadStringCompleted);
        w.DownloadStringAsync(sub4);
        MessageBox.Show("done");

        }
    void wc_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
    {
    string fres = e.Result;// here e.result was � 
    }

And then I want to deserialize e.result. 然后我想反序化e.result。 My code is working properly for any other json url. 我的代码适用于任何其他json url。 And since I am working on windows phone app so I am unable to use other webcilent methods such as DownloadData and DownloadString. 因为我正在使用Windows Phone应用程序,所以我无法使用其他的网络静音方法,如DownloadData和DownloadString。 Also i have seen many conversions between utf8 and unicode but none of them worked. 此外,我看到utf8和unicode之间的许多转换,但没有一个工作。 Can anyone please help?? 有人可以帮忙吗?

The API you are hitting serves gzipped content, and that is what you are seeing as garbage text. 您正在使用的API提供gzip压缩内容,这就是您所看到的垃圾文本。 You need to unzip the content before using it. 您需要在使用之前解压缩内容。 You can tell this from the header: 你可以从标题中说出来:

Content-Encoding: gzip

Unfortunately, the last time I checked, there was no built in support for GZip'ed responses in Windows Phone. 不幸的是,我最后一次检查时,没有内置支持Windows Phone中的GZip'ed响应。 It should not be too hard to create a workaround. 创建一个变通方法应该不会太难。 When googling, results suggests that the lowest impact solution is adding the SharpGIS.GZipWebClient library from NuGet and use the GZip support from there. 谷歌搜索结果表明,影响最小的解决方案是从NuGet添加SharpGIS.GZipWebClient库并使用GZip支持。

您只需按照以下链接,它将为您提供有关如何使用和解析服务器中的json数据的完整说明如何在wp7应用程序中使用Json服务

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM