Parsing JSON on Windows Phone 7

谁说我不能喝 提交于 2019-12-13 13:06:28

问题


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.

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.

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?

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();

Update 2: The following also complains:

using System.Runtime.Serialization.Json;

The error:

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

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

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

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


回答1:


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

It's caught quite a few people out.

Glad you seem to have got this working.




回答2:


Also, if you use the DataContract attribute, this is in the System.Runtime.Serialization namespace and in System.Runtime.Serialization.dll assembly.



来源:https://stackoverflow.com/questions/3999117/parsing-json-on-windows-phone-7

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!