在Metro应用中反序列化JSON时出现错误 [英] Getting error on deserializing json in metro app

查看:119
本文介绍了在Metro应用中反序列化JSON时出现错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我正在Metro应用程序中工作,以显示youtube视频,并且用户可以播放视频或对视频进行评分.我正在使用这个uri
http://gdata.youtube.com/feeds/api/videos/ADos_xW4_J0?v=2&alt=jsonc

并获取json响应,但是现在当我尝试将其反序列化为c#类时,出现了错误.我正在使用newtonsoft将json转换为类.

我使用的方法是

Hi,
I am working in a metro app to show youtube videos and user can play or rate video. I am using this uri
http://gdata.youtube.com/feeds/api/videos/ADos_xW4_J0?v=2&alt=jsonc

and get json response but now when I am trying to deserialize it into c# class I am getting error. I am using newtonsoft to convert json to class.

Method which I am using is

public static T Deserialize<T>(string json)
{
    T obj = Activator.CreateInstance<T>();
    using (MemoryStream ms = new MemoryStream(Encoding.Unicode.GetBytes(json)))
    {
        obj = (T)JsonConvert.DeserializeObject(json, obj.GetType());
        return obj;
    }
}


此方法将json数据转换为c#类.
还有其他方法可以从youtube获取视频详细信息.

添加了代码块[/编辑]


This method convert json data to c# class.
Is there any other way to get video details from youtube.

Code block added[/Edit]

推荐答案


谢天谢地,这没什么大不了的.我刚刚添加了newtonsoft dll参考,可能是因为我从软件包控制台安装newtonsoft软件包时就解决了所有问题,没有引发任何错误.
Hi,
Thank god its not a big deal. I just added the newtonsoft dll reference, may be this is the problem beacause when I install the newtonsoft package from package console everything gets solved, no error is thrown.


这篇关于在Metro应用中反序列化JSON时出现错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆