Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Parsing JSON on Windows Phone 7

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.

like image 212
Nick Heiner Avatar asked Oct 22 '10 16:10

Nick Heiner


1 Answers

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.

like image 55
Matt Lacey Avatar answered Nov 09 '22 00:11

Matt Lacey