在Windows Phone 7上解析JSON [英] Parsing JSON on Windows Phone 7

查看:151
本文介绍了在Windows Phone 7上解析JSON的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在Windows Phone 7上执行一些简单的JSON操作.JSON.NET看起来不错,但是当我尝试为其添加引用时,VS2010会抱怨.

I'm trying to do some simple JSON manipulation on the Windows Phone 7. JSON.NET looks great, but VS2010 complains when I try to add a reference to it.

它允许我添加Silverlight dll,但警告我,它可能导致奇怪的应用程序行为,因此我怀疑它是否真的可以工作.

It let me add the Silverlight dll, but warned me that it could result in weird app behavior, so I'm skeptical that it would actually work.

看起来像是对数据进行序列化和反序列化的一种好方法,但是我实际上需要查询它.我可以使用这种技术将其序列化为IQueryable,然后在其上使用LINQ吗?我可以以某种方式将JSON转换为XML并使用LINQ吗?

This looks like a fine way to serialize and deserialize data, but I need to actually query it. Could I just use this technique to serialize it to a IQueryable, then use LINQ on it? Can I somehow convert the JSON to XML and use LINQ?

还是我应该自己做一些令人讨厌的字符串操作?

Or should I do hacky and sad string manipulation myself?

更新:由于某种原因,我什至无法让VS2010识别DataContractJsonSerializer:

Update: For some reason, I can't even get VS2010 to recognize DataContractJsonSerializer:

        // works
        DataContractSerializer ser1 = new DataContractSerializer();

        // the type or namespace 'DataContractJsonSerializer' could not be found ...
        DataContractJsonSerializer ser = new DataContractJsonSerializer();

更新2 :以下内容也有抱怨:

Update 2: The following also complains:

using System.Runtime.Serialization.Json;

错误:

类型或名称空间名称'Json'确实 在命名空间中不存在 'System.Runtime.Serialization'(是 您缺少装配参考吗?)

The type or namespace name 'Json' does not exist in the namespace 'System.Runtime.Serialization' (are you missing an assembly reference?)

我做错什么了吗,或者wp7不支持JSON?

Am I doing something wrong, or is JSON not supported in wp7?

更新3 :看起来DataContractJsonSerializer在System.Servicemodel.Web命名空间中.

Update 3: Looks like DataContractJsonSerializer is in the System.Servicemodel.Web namespace.

更新4 :我添加了对Silverlight JSON.NET dll的引用,目前看来工作正常.手指交叉.

Update 4: I added a reference to the Silverlight JSON.NET dll, and it appears to be working fine for now. Fingers crossed.

推荐答案

是的,根据您的Update 3(几乎):
DataContractJsonSerializerSystem.Servicemodel.Web.dll程序集中,但在System.Runtime.Serialization.Json命名空间中.

Yes, as per your Update 3 (almost):
DataContractJsonSerializer is in the System.Servicemodel.Web.dll assembly, but in the System.Runtime.Serialization.Json namespace.

它吸引了很多人.

很高兴您似乎已经成功了.

Glad you seem to have got this working.

这篇关于在Windows Phone 7上解析JSON的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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