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 mixe开发者_Go百科d 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
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'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.
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
精彩评论