English 中文(简体)
System.Json namespace missing from Windows Phone 7
原标题:

During a Mix10 presentation, the presenter (Charlie Kindel) said that when writing Silverlight based apps for WP7 you get all of Silverlight 3.0 with some of Silverlight 4.0 mixed in.

Why then is System.Json missing? It was included in Silverlight 3.0, and is included in Silverlight 4.0.

Windows Phone 7 Class Library Reference

最佳回答

I m not sure why either , but it says on this link that the namespace is not supported

See Features Supported in Silverlight for Windows Phone.

问题回答

Add a reference to System.ServiceModel.Web as well as the reference to System.Runtime.Serialization and it should work. System.ServiceModel.Web appears to add .JSON to the Serialization namespace.

You could also try using the DataContractJsonSerializer, which is definitely present in the MIX RC tools http://msdn.microsoft.com/en-us/library/system.runtime.serialization.json.datacontractjsonserializer.aspx.

Seems that JSON is supported in Windows Phone 7 in the System.Runtime.Serialization.Json namespace, hopefully this will be useful, even though this question is a month old! Information from the TechDays in London (via Twitter) was not there personally.


Just an update is that the namespace and class I quoted here was incorrect so here is the correct namespace and class:

System.Servicemodel.Web and the Class is DataContractJsonSerializer for JSON Serialisation and Deserialisation on Windows Phone 7 - sorry about the inaccurate reply I have corrected after a comment posted here.

While the DataContractJsonSerializer is available in Silverlight, it doesn t appear to be available on the Windows Phone 7 CTP. Maybe it will show up later, but its not there now. (I have tried using it in code, the System.Runtime.Serialization assembly does not include this class and the official documentation says that JSON serialization is something that is in Silverlight, but not in Windows Phone 7.)

However, I was able to take the JSON.NET library and create a WP7 library project out of it. This got me a JSON infrastructure on the Phone that I m using successfully.

In our Windows Phone 7 project, we are using James Newton-Kings JSON.Net Library. Just download the code and add a reference to Newtonsoft.Json.Silverlight. Works like a charm.

I can t tell you why the JSON namespace isn t in there but perhaps you could use the OData Client Library for Windows Phone 7 which supports JSON:

http://www.microsoft.com/downloads/details.aspx?FamilyID=b251b247-70ca-4887-bab6-dccdec192f8d&displaylang=en





相关问题
Silverlight Rich text box control

Our team decided that we need our own custom Rich text box control for Silverlight app we are developing. We looked at existing controls mentioned at A good rich text control for Silverlight but ...

Silverlight ImageBrush not rendering (with Bing Map Control)

I m trying to add an image to a Pushpin instance from the Silverlight Bing Map Control, but I can t seem to get it to render (the pushpin renders fine). This is probably a general WPF question rather ...

Silverlight OpenFileDialog DoEvents equivalent

I m processing large files after they are selected by the user. My code looks like the following: if (FileDialog.ShowDialog() == true) { // process really big file } This freezes up the UI so ...

list of controls with templates in silverlight

Does anyone know where to find a list of controls that you can set the template on in Silverlight? I ve wasted several hours now trying to create control templates only to find that the control doesn ...

Silverlight, Updating the UI during processing

I have a simple silverlight multifile upload application, and i want to provide the user with some feedback, right now its only in a test phase and i dont have the webservice. Somehow i cant get the ...

Silverlight 3 - FindName returns null

This looks a bug to me.. Using Silverlight 3 and i have a user control defined in XAML and trying to access the object during runtime returns a null. <Grid> <common:CommonGridEditPanel x:...

silverlight 3 collection binding

Someone please help me understand why this binding does not work... I have a class called SelectionManager with a property called dates which is populated by a WCF service. The property is an ...

热门标签