SilverlightShow: JSON serialization and deserialization in Silverlight Comments
http://www.silverlightshow.net/
Silverlight articles, Silverlight tutorials, Silverlight videos, Silverlight samples
SilverlightShow.net
http://www.rssboard.org/rss-specification
Argotic Syndication Framework 2008.0.2.0, http://www.codeplex.com/Argotic
en-US
estoychev@completit.com (Emil Stoychev)
-
RE: JSON serialization and deserialization in Silverlight
<p>If you want code to serialize and deserialize Java objects, without any configuration, extra definition files, etc. check out <a href="http://code.google.com/p/json-io/">http://code.google.com/p/json-io/</a>. We use this code on our servers to process JSON sent by our clients, and to send back JSON responses to our client applications. We've found this to handle anything object graph we've thrown at it, and it is extremely quick.</p>
http://www.silverlightshow.net/items/JSON-serialization-and-deserialization-in-Silverlight.aspx#comment4946
Jim
http://www.silverlightshow.net/items/JSON-serialization-and-deserialization-in-Silverlight.aspx
Tue, 23 Nov 2010 17:02:59 GMT
-
RE: JSON serialization and deserialization in Silverlight
<p><span style="font-family: calibri;">This will work in SL3 also.</span></p>
<p><span style="font-family: calibri;">You only need to reference <strong>System.ServiceModel.Web</strong> to use the DataContractJsonSerializer, not the System.Runtime.Serialization.Json.</span></p>
http://www.silverlightshow.net/items/JSON-serialization-and-deserialization-in-Silverlight.aspx#comment4870
Mani
http://www.silverlightshow.net/items/JSON-serialization-and-deserialization-in-Silverlight.aspx
Tue, 16 Nov 2010 15:51:53 GMT
-
RE: JSON serialization and deserialization in Silverlight
You do not need to close/dispose your stream in the serialise example, the reader will do that for you. In your case you risk disposing the stream twice.
http://www.silverlightshow.net/items/JSON-serialization-and-deserialization-in-Silverlight.aspx#comment4846
Robert MacLean
http://www.silverlightshow.net/items/JSON-serialization-and-deserialization-in-Silverlight.aspx
Thu, 11 Nov 2010 11:28:32 GMT
-
RE: JSON serialization and deserialization in Silverlight
<p>don't know if anyone tried the C# code but it doesn't compile and it generates XML not JSON.</p>
<p>Also, it always serializes a list that includes the object type and instantiates that type when deserializing. </p>
<p>Try this:</p>
<p>
<div style="border: 1px solid #7f9db9; overflow-y: auto;" class="reCodeBlock">
<div style="background-color: #ffffff;"><span style="margin-left: 0px ! important;"><code style="color: #006699; font-weight: bold;">public</code> <code style="color: #006699; font-weight: bold;">string</code> <code style="color: #000000;">GetStringFromMemoryStream(MemoryStream m)</code></span></div>
<div style="background-color: #f8f8f8;"><span style="margin-left: 0px ! important;"><code style="color: #000000;">{</code></span></div>
<div style="background-color: #ffffff;"><span><code> </code><span style="margin-left: 6px ! important;"><code style="color: #006699; font-weight: bold;">if</code> <code style="color: #000000;">((m == </code><code style="color: #006699; font-weight: bold;">null</code><code style="color: #000000;">) || m.Length == 0)</code></span></span></div>
<div style="background-color: #f8f8f8;"><span><code> </code><span style="margin-left: 6px ! important;"><code style="color: #000000;">{</code></span></span></div>
<div style="background-color: #ffffff;"><span><code> </code><span style="margin-left: 12px ! important;"><code style="color: #006699; font-weight: bold;">return</code> <code style="color: blue;">""</code><code style="color: #000000;">;</code></span></span></div>
<div style="background-color: #f8f8f8;"><span><code> </code><span style="margin-left: 6px ! important;"><code style="color: #000000;">}</code></span></span></div>
<div style="background-color: #ffffff;"><span><code> </code><span style="margin-left: 6px ! important;"><code style="color: #000000;">m.Flush();</code></span></span></div>
<div style="background-color: #f8f8f8;"><span><code> </code><span style="margin-left: 6px ! important;"><code style="color: #000000;">m.Position = 0;</code></span></span></div>
<div style="background-color: #ffffff;"><span><code> </code><span style="margin-left: 6px ! important;"><code style="color: #000000;">var UTF8 = UTF8Encoding.UTF8;</code></span></span></div>
<div style="background-color: #f8f8f8;"><span><code> </code><span style="margin-left: 6px ! important;"><code style="color: #000000;">StreamReader sr = </code><code style="color: #006699; font-weight: bold;">new</code> <code style="color: #000000;">StreamReader(m, UTF8Encoding.UTF8);</code></span></span></div>
<div style="background-color: #ffffff;"><span><code> </code><span style="margin-left: 6px ! important;"><code style="color: #006699; font-weight: bold;">string</code> <code style="color: #000000;">s = sr.ReadToEnd();</code></span></span></div>
<div style="background-color: #f8f8f8;"><span><code> </code><span style="margin-left: 6px ! important;"><code style="color: #006699; font-weight: bold;">return</code> <code style="color: #000000;">s;</code></span></span></div>
<div style="background-color: #ffffff;"><span style="margin-left: 0px ! important;"><code style="color: #000000;">}</code></span></div>
<div style="background-color: #f8f8f8;"><span style="margin-left: 0px ! important;"><code style="color: #006699; font-weight: bold;">public</code> <code style="color: #000000;">MemoryStream GetMemoryStreamFromString(</code><code style="color: #006699; font-weight: bold;">string</code> <code style="color: #000000;">s)</code></span></div>
<div style="background-color: #ffffff;"><span style="margin-left: 0px ! important;"><code style="color: #000000;">{</code></span></div>
<div style="background-color: #f8f8f8;"><span><code> </code><span style="margin-left: 6px ! important;"><code style="color: #006699; font-weight: bold;">if</code> <code style="color: #000000;">((s == </code><code style="color: #006699; font-weight: bold;">null</code><code style="color: #000000;">) || s.Length == 0)</code></span></span></div>
<div style="background-color: #ffffff;"><span><code> </code><span style="margin-left: 6px ! important;"><code style="color: #000000;">{</code></span></span></div>
<div style="background-color: #f8f8f8;"><span><code> </code><span style="margin-left: 12px ! important;"><code style="color: #006699; font-weight: bold;">return</code> <code style="color: #006699; font-weight: bold;">null</code><code style="color: #000000;">;</code></span></span></div>
<div style="background-color: #ffffff;"><span><code> </code><span style="margin-left: 6px ! important;"><code style="color: #000000;">}</code></span></span></div>
<div style="background-color: #f8f8f8;"><span><code> </code><span style="margin-left: 6px ! important;"><code style="color: #000000;">var a = System.Text.Encoding.UTF8.GetBytes(s);</code></span></span></div>
<div style="background-color: #ffffff;"><span><code> </code><span style="margin-left: 6px ! important;"><code style="color: #000000;">System.IO.MemoryStream m = </code><code style="color: #006699; font-weight: bold;">new</code> <code style="color: #000000;">System.IO.MemoryStream(a, </code><code style="color: #006699; font-weight: bold;">true</code><code style="color: #000000;">);</code></span></span></div>
<div style="background-color: #f8f8f8;"><span><code> </code><span style="margin-left: 6px ! important;"><code style="color: #000000;">m.Position = 0;</code></span></span></div>
<div style="background-color: #ffffff;"><span><code> </code><span style="margin-left: 6px ! important;"><code style="color: #006699; font-weight: bold;">return</code> <code style="color: #000000;">m;</code></span></span></div>
<div style="background-color: #f8f8f8;"><span style="margin-left: 0px ! important;"><code style="color: #000000;">}</code></span></div>
<div style="background-color: #ffffff;"><span style="margin-left: 0px ! important;"><code style="color: #006699; font-weight: bold;">public</code> <code style="color: #006699; font-weight: bold;">string</code> <code style="color: #000000;">Serialize(</code><code style="color: #006699; font-weight: bold;">object</code> <code style="color: #000000;">BaseType)</code></span></div>
<div style="background-color: #f8f8f8;"><span style="margin-left: 0px ! important;"><code style="color: #000000;">{</code></span></div>
<div style="background-color: #ffffff;"><span><code> </code><span style="margin-left: 6px ! important;"><code style="color: #000000;">var ExactName = BaseType.GetType().AssemblyQualifiedName;</code></span></span></div>
<div style="background-color: #f8f8f8;"><span><code> </code><span style="margin-left: 6px ! important;"><code style="color: #006699; font-weight: bold;">string</code> <code style="color: #000000;">Ser = p_Serialize(BaseType);</code></span></span></div>
<div style="background-color: #ffffff;"><span><code> </code><span style="margin-left: 6px ! important;"><code style="color: #000000;">List<</code><code style="color: #006699; font-weight: bold;">string</code><code style="color: #000000;">> oList = </code><code style="color: #006699; font-weight: bold;">new</code> <code style="color: #000000;">List<</code><code style="color: #006699; font-weight: bold;">string</code><code style="color: #000000;">>();</code></span></span></div>
<div style="background-color: #f8f8f8;"><span><code> </code><span style="margin-left: 6px ! important;"><code style="color: #000000;">oList.Add(ExactName);</code></span></span></div>
<div style="background-color: #ffffff;"><span><code> </code><span style="margin-left: 6px ! important;"><code style="color: #000000;">oList.Add(Ser);</code></span></span></div>
<div style="background-color: #f8f8f8;"><span><code> </code><span style="margin-left: 6px ! important;"><code style="color: #006699; font-weight: bold;">return</code> <code style="color: #000000;">p_Serialize(oList);</code></span></span></div>
<div style="background-color: #ffffff;"><span style="margin-left: 0px ! important;"><code style="color: #000000;">}</code></span></div>
<div style="background-color: #f8f8f8;"><span style="margin-left: 0px ! important;"><code style="color: #006699; font-weight: bold;">private</code> <code style="color: #006699; font-weight: bold;">string</code> <code style="color: #000000;">p_Serialize(</code><code style="color: #006699; font-weight: bold;">object</code> <code style="color: #000000;">BaseType)</code></span></div>
<div style="background-color: #ffffff;"><span style="margin-left: 0px ! important;"><code style="color: #000000;">{</code></span></div>
<div style="background-color: #f8f8f8;"><span><code> </code><span style="margin-left: 6px ! important;"><code style="color: #006699; font-weight: bold;">if</code> <code style="color: #000000;">(BaseType == </code><code style="color: #006699; font-weight: bold;">null</code><code style="color: #000000;">)</code></span></span></div>
<div style="background-color: #ffffff;"><span><code> </code><span style="margin-left: 6px ! important;"><code style="color: #000000;">{</code></span></span></div>
<div style="background-color: #f8f8f8;"><span><code> </code><span style="margin-left: 12px ! important;"><code style="color: #006699; font-weight: bold;">throw</code> <code style="color: #006699; font-weight: bold;">new</code> <code style="color: #000000;">ArgumentNullException(</code><code style="color: blue;">"No object to serialize"</code><code style="color: #000000;">);</code></span></span></div>
<div style="background-color: #ffffff;"><span><code> </code><span style="margin-left: 6px ! important;"><code style="color: #000000;">}</code></span></span></div>
<div style="background-color: #f8f8f8;"><span><code> </code><span style="margin-left: 6px ! important;"><code style="color: #000000;">DataContractJsonSerializer dcs = </code><code style="color: #006699; font-weight: bold;">new</code> <code style="color: #000000;">DataContractJsonSerializer(BaseType.GetType());</code></span></span></div>
<div style="background-color: #ffffff;"><span><code> </code><span style="margin-left: 6px ! important;"><code style="color: #000000;">MemoryStream ms = </code><code style="color: #006699; font-weight: bold;">new</code> <code style="color: #000000;">MemoryStream();</code></span></span></div>
<div style="background-color: #f8f8f8;"><span><code> </code><span style="margin-left: 6px ! important;"><code style="color: #000000;">dcs.WriteObject(ms, BaseType);</code></span></span></div>
<div style="background-color: #ffffff;"><span><code> </code><span style="margin-left: 6px ! important;"><code style="color: #006699; font-weight: bold;">return</code> <code style="color: #000000;">Encoding.UTF8.GetString(ms.GetBuffer(), 0, (</code><code style="color: #006699; font-weight: bold;">int</code><code style="color: #000000;">)ms.Position);</code></span></span></div>
<div style="background-color: #f8f8f8;"><span style="margin-left: 0px ! important;"><code style="color: #000000;">}</code></span></div>
<div style="background-color: #ffffff;"><span style="margin-left: 0px ! important;"><code style="color: #006699; font-weight: bold;">public</code> <code style="color: #006699; font-weight: bold;">object</code> <code style="color: #000000;">Deserialize(</code><code style="color: #006699; font-weight: bold;">string</code> <code style="color: #000000;">s)</code></span></div>
<div style="background-color: #f8f8f8;"><span style="margin-left: 0px ! important;"><code style="color: #000000;">{</code></span></div>
<div style="background-color: #ffffff;"><span><code> </code><span style="margin-left: 6px ! important;"><code style="color: #000000;">List<</code><code style="color: #006699; font-weight: bold;">string</code><code style="color: #000000;">> oList = </code><code style="color: #006699; font-weight: bold;">new</code> <code style="color: #000000;">List<</code><code style="color: #006699; font-weight: bold;">string</code><code style="color: #000000;">>();</code></span></span></div>
<div style="background-color: #f8f8f8;"><span><code> </code><span style="margin-left: 6px ! important;"><code style="color: #000000;">oList = (List<</code><code style="color: #006699; font-weight: bold;">string</code><code style="color: #000000;">>)p_Deserialize(s, oList);</code></span></span></div>
<div style="background-color: #ffffff;"><span><code> </code><span style="margin-left: 6px ! important;"><code style="color: #006699; font-weight: bold;">object</code> <code style="color: #000000;">Instance = Activator.CreateInstance(Type.GetType(oList[0]));</code></span></span></div>
<div style="background-color: #f8f8f8;"><span><code> </code><span style="margin-left: 6px ! important;"><code style="color: #006699; font-weight: bold;">return</code> <code style="color: #000000;">p_Deserialize(oList[1], Instance);</code></span></span></div>
<div style="background-color: #ffffff;"><span style="margin-left: 0px ! important;"><code style="color: #000000;">}</code></span></div>
<div style="background-color: #f8f8f8;"><span style="margin-left: 0px ! important;"><code style="color: #006699; font-weight: bold;">public</code> <code style="color: #006699; font-weight: bold;">object</code> <code style="color: #000000;">p_Deserialize(</code><code style="color: #006699; font-weight: bold;">string</code> <code style="color: #000000;">s, </code><code style="color: #006699; font-weight: bold;">object</code> <code style="color: #000000;">BaseType)</code></span></div>
<div style="background-color: #ffffff;"><span style="margin-left: 0px ! important;"><code style="color: #000000;">{</code></span></div>
<div style="background-color: #f8f8f8;"><span><code> </code><span style="margin-left: 6px ! important;"><code style="color: #000000;">DataContractJsonSerializer dcs = </code><code style="color: #006699; font-weight: bold;">new</code> <code style="color: #000000;">DataContractJsonSerializer(BaseType.GetType());</code></span></span></div>
<div style="background-color: #ffffff;"><span><code> </code><span style="margin-left: 6px ! important;"><code style="color: #000000;">MemoryStream m = GetMemoryStreamFromString(s);</code></span></span></div>
<div style="background-color: #f8f8f8;"><span><code> </code><span style="margin-left: 6px ! important;"><code style="color: #000000;">BaseType = dcs.ReadObject(m);</code></span></span></div>
<div style="background-color: #ffffff;"><span><code> </code><span style="margin-left: 6px ! important;"><code style="color: #006699; font-weight: bold;">return</code> <code style="color: #000000;">BaseType;</code></span></span></div>
<div style="background-color: #f8f8f8;"><span style="margin-left: 0px ! important;"><code style="color: #000000;">}</code></span></div>
</div>
</p>
<p></p>
http://www.silverlightshow.net/items/JSON-serialization-and-deserialization-in-Silverlight.aspx#comment3368
Toby
http://www.silverlightshow.net/items/JSON-serialization-and-deserialization-in-Silverlight.aspx
Sat, 10 Apr 2010 00:46:23 GMT
-
RE: JSON serialization and deserialization in Silverlight
<p>| the C# version...</p>
<p>using System.IO;<br />
using System.Text;<br />
using System.Runtime.Serialization;</p>
<p>public class Conversion<br />
{<br />
public string GetStringFromMemoryStream(MemoryStream m)<br />
{<br />
if ((m == null) | m.Length == 0) {<br />
return "";<br />
}<br />
m.Flush();<br />
m.Position = 0;<br />
var UTF8 = UTF8Encoding.UTF8;<br />
StreamReader sr = new StreamReader(m, UTF8Encoding.UTF8);<br />
string s = sr.ReadToEnd();<br />
return s;<br />
}<br />
public MemoryStream GetMemoryStreamFromString(string s)<br />
{<br />
if ((s == null) | s.Length == 0) {<br />
return null;<br />
}<br />
var a = System.Text.Encoding.UTF8.GetBytes(s);<br />
System.IO.MemoryStream m = new System.IO.MemoryStream(a, true);<br />
m.Position = 0;<br />
return m;<br />
}<br />
public string Serialize(object BaseType)<br />
{<br />
var ExactName = BaseType.GetType.AssemblyQualifiedName;<br />
string Ser = p_Serialize(BaseType);<br />
List<string> oList = new List<string>();<br />
oList.Add(ExactName);<br />
oList.Add(Ser);<br />
return p_Serialize(oList);<br />
}<br />
private string p_Serialize(object BaseType)<br />
{<br />
if (BaseType == null) {<br />
throw new ArgumentNullException("your Object IsNothing to me!");<br />
}<br />
DataContractSerializer dcs = new DataContractSerializer(BaseType.GetType());<br />
MemoryStream ms = new MemoryStream();<br />
dcs.WriteObject(ms, BaseType);<br />
return Encoding.UTF8.GetString(ms.GetBuffer(), 0, (int)ms.Position);<br />
}<br />
public object Deserialize(string s)<br />
{<br />
List<string> oList = new List<string>();<br />
oList = p_Deserialize(s, oList);<br />
object Instance = Activator.CreateInstance(Type.GetType(oList.Item(0)));<br />
return p_Deserialize(oList.Item(1), Instance);<br />
}<br />
public object p_Deserialize(string s, object BaseType)<br />
{<br />
DataContractSerializer dcs = new DataContractSerializer(BaseType.GetType());<br />
MemoryStream m = GetMemoryStreamFromString(s);<br />
BaseType = dcs.ReadObject(m);<br />
return BaseType;<br />
}<br />
}</p>
http://www.silverlightshow.net/items/JSON-serialization-and-deserialization-in-Silverlight.aspx#comment2548
Ross Brodskiy
http://www.silverlightshow.net/items/JSON-serialization-and-deserialization-in-Silverlight.aspx
Thu, 15 Oct 2009 02:46:32 GMT
-
RE: JSON serialization and deserialization in Silverlight
<p>Yes it doesn't work with 3.0 :( so here is new utility class I just had to write...</p>
<p>Imports System.IO<br />
Imports System.Text<br />
Imports System.Runtime.Serialization</p>
<p>Public Class Conversion<br />
Public Function GetStringFromMemoryStream(ByVal m As MemoryStream) As String<br />
If (m Is Nothing) Or m.Length = 0 Then<br />
Return ""<br />
End If<br />
m.Flush()<br />
m.Position = 0<br />
Dim UTF8 = UTF8Encoding.UTF8<br />
Dim sr As New StreamReader(m, UTF8Encoding.UTF8)<br />
Dim s As String = sr.ReadToEnd()<br />
Return s<br />
End Function<br />
Public Function GetMemoryStreamFromString(ByVal s As String) As MemoryStream<br />
If (s Is Nothing) Or s.Length = 0 Then<br />
Return Nothing<br />
End If<br />
Dim a = System.Text.Encoding.UTF8.GetBytes(s)<br />
Dim m As New System.IO.MemoryStream(a, True)<br />
m.Position = 0<br />
Return m<br />
End Function<br />
Public Function Serialize(ByVal BaseType As Object) As String<br />
Dim ExactName = BaseType.GetType.AssemblyQualifiedName<br />
Dim Ser As String = p_Serialize(BaseType)<br />
Dim oList As New List(Of String)<br />
oList.Add(ExactName)<br />
oList.Add(Ser)<br />
Return p_Serialize(oList)<br />
End Function<br />
Private Function p_Serialize(ByVal BaseType As Object) As String<br />
If BaseType Is Nothing Then<br />
Throw New ArgumentNullException("your Object IsNothing to me!")<br />
End If<br />
Dim dcs As New DataContractSerializer(BaseType.[GetType]())<br />
Dim ms As New MemoryStream()<br />
dcs.WriteObject(ms, BaseType)<br />
Return Encoding.UTF8.GetString(ms.GetBuffer(), 0, CInt(ms.Position))<br />
End Function<br />
Public Function Deserialize(ByVal s As String) As Object<br />
Dim oList As New List(Of String)<br />
oList = p_Deserialize(s, oList)<br />
Dim Instance As Object = Activator.CreateInstance(Type.GetType(oList.Item(0)))<br />
Return p_Deserialize(oList.Item(1), Instance)<br />
End Function<br />
Public Function p_Deserialize(ByVal s As String, ByVal BaseType As Object) As Object<br />
Dim dcs As New DataContractSerializer(BaseType.GetType())<br />
Dim m As MemoryStream = GetMemoryStreamFromString(s)<br />
BaseType = dcs.ReadObject(m)<br />
Return BaseType<br />
End Function<br />
End Class</p>
<p> </p>
http://www.silverlightshow.net/items/JSON-serialization-and-deserialization-in-Silverlight.aspx#comment2547
Ross Brodskiy
http://www.silverlightshow.net/items/JSON-serialization-and-deserialization-in-Silverlight.aspx
Thu, 15 Oct 2009 02:44:32 GMT
-
RE: JSON serialization and deserialization in Silverlight
Do not work with SL3 release.<br />
<br />
One Idéa ?<br />
<br />
Yvan
http://www.silverlightshow.net/items/JSON-serialization-and-deserialization-in-Silverlight.aspx#comment2314
Navedac
http://www.silverlightshow.net/items/JSON-serialization-and-deserialization-in-Silverlight.aspx
Sun, 06 Sep 2009 16:10:08 GMT
-
RE: JSON serialization and deserialization in Silverlight
<p>Heres much more organized way of doing the same, plus it give you ability to Serialize and deSerialize into that precise same object! Thats can be important in may instances.Imports System<br />
Imports System.Xml<br />
Imports System.Xml.Linq<br />
Imports System.Collections.Generic<br />
Imports System.Runtime.Serialization.Json</p>
<p>Imports System.IO<br />
Imports System.Text<br />
Imports System.Runtime.Serialization</p>
<p >Partial Public Class Serializer<br />
''' <summary> <br />
''' Takes a MemoryStream and creates string <br />
''' </summary> <br />
''' <param name="m"></param> <br />
''' <returns></returns> <br />
Public Function GetStringFromMemoryStream(ByVal m As MemoryStream) As String<br />
If (m Is Nothing) Or m.Length = 0 Then<br />
Return ""<br />
End If<br />
m.Flush()<br />
m.Position = 0<br />
Dim UTF8 = UTF8Encoding.UTF8<br />
Dim sr As New StreamReader(m, UTF8Encoding.UTF8)<br />
Dim s As String = sr.ReadToEnd()<br />
Return s<br />
End Function<br />
''' <summary> <br />
''' Takes a string and creates MemoryStream <br />
''' </summary> <br />
''' <param name="s"></param> <br />
''' <returns></returns> <br />
Public Function GetMemoryStreamFromString(ByVal s As String) As MemoryStream<br />
If (s Is Nothing) Or s.Length = 0 Then<br />
Return Nothing<br />
End If<br />
Dim a = System.Text.Encoding.UTF8.GetBytes(s)<br />
Dim m As New System.IO.MemoryStream(a, True)<br />
m.Position = 0<br />
Return m<br />
End Function<br />
''' <summary> <br />
''' JSON Serialize an object into <br />
''' </summary> <br />
''' <param name="BaseType"></param> <br />
''' <returns></returns> <br />
Public Function Serialize(ByVal BaseType As Object) As String<br />
Dim ExactName = BaseType.GetType.AssemblyQualifiedName<br />
Dim Sur As String = p_Serialize(BaseType)<br />
Dim oList As New List(Of String)<br />
oList.Add(ExactName)<br />
oList.Add(Sur)<br />
Return p_Serialize(oList)<br />
End Function<br />
Private Function p_Serialize(ByVal BaseType As Object) As String<br />
Dim ser As New DataContractJsonSerializer(BaseType.[GetType]())<br />
Dim m As New MemoryStream()<br />
m.Position = 0<br />
ser.WriteObject(m, BaseType)<br />
Return GetStringFromMemoryStream(m)<br />
End Function<br />
''' <summary> <br />
''' JSON Deserialize <br />
''' </summary> <br />
''' <param name="s"></param> <br />
''' <param name="BaseType"></param> <br />
''' <returns></returns> <br />
Public Function Deserialize(ByVal s As String) As Object<br />
Dim oList As New List(Of String)<br />
oList = p_Deserialize(s, oList.GetType)<br />
Return p_Deserialize(oList.Item(1), Type.GetType(oList.Item(0)))</p>
<p> End Function</p>
<p> Private Function p_Deserialize(ByVal s As String, ByVal BaseType As Object) As Object<br />
Dim ser As New DataContractJsonSerializer(BaseType)<br />
Dim m As MemoryStream = GetMemoryStreamFromString(s)<br />
m.Position = 0</p>
<p> Return ser.ReadObject(m)<br />
End Function<br />
End Class</p>
http://www.silverlightshow.net/items/JSON-serialization-and-deserialization-in-Silverlight.aspx#comment1507
Ross Brodskiy
http://www.silverlightshow.net/items/JSON-serialization-and-deserialization-in-Silverlight.aspx
Thu, 23 Apr 2009 16:38:17 GMT
-
RE: JSON serialization and deserialization in Silverlight
гавно
http://www.silverlightshow.net/items/JSON-serialization-and-deserialization-in-Silverlight.aspx#comment1407
ad
http://www.silverlightshow.net/items/JSON-serialization-and-deserialization-in-Silverlight.aspx
Thu, 02 Apr 2009 08:32:47 GMT
-
RE: JSON serialization and deserialization in Silverlight
<p>Good stuff.</p>
http://www.silverlightshow.net/items/JSON-serialization-and-deserialization-in-Silverlight.aspx#comment602
Satya N.
http://www.silverlightshow.net/items/JSON-serialization-and-deserialization-in-Silverlight.aspx
Fri, 31 Oct 2008 04:54:23 GMT
-
RE: JSON serialization and deserialization in Silverlight
<p>Beautiful - works like a charm. Thank you!</p>
http://www.silverlightshow.net/items/JSON-serialization-and-deserialization-in-Silverlight.aspx#comment319
Bradford
http://www.silverlightshow.net/items/JSON-serialization-and-deserialization-in-Silverlight.aspx
Thu, 21 Aug 2008 19:42:01 GMT
-
RE: JSON serialization and deserialization in Silverlight
<p>Cool and clear; Thanks</p>
http://www.silverlightshow.net/items/JSON-serialization-and-deserialization-in-Silverlight.aspx#comment312
Sergei meleshchuk
http://www.silverlightshow.net/items/JSON-serialization-and-deserialization-in-Silverlight.aspx
Wed, 20 Aug 2008 10:56:47 GMT