added samples
[windows-sources.git] / sdk / samples / WCFSamples / TechnologySamples / Basic / Ajax / JsonSerialization / VB / client / client.vb
blobadfe6904f5e113cef1fa8e6462d76a4db6464745
1 ' Copyright (c) Microsoft Corporation. All rights reserved.
3 Imports System
4 Imports System.IO
5 Imports System.Runtime.Serialization
6 Imports System.Runtime.Serialization.Json
8 Namespace Microsoft.Ajax.Samples
10 Class Sample
11 Public Shared Sub Main()
12 Dim p As New Person()
13 p.name = "John"
14 p.age = 42
16 Dim stream1 As New MemoryStream()
18 'Serialize the Person object to a memory stream using DataContractJsonSerializer.
19 Dim ser As New DataContractJsonSerializer(GetType(Person))
20 ser.WriteObject(stream1, p)
22 'Show the JSON output
23 stream1.Position = 0
24 Dim sr As New StreamReader(stream1)
25 Console.Write("JSON form of Person object: ")
26 Console.WriteLine(sr.ReadToEnd())
28 'Deserialize the JSON back into a new Person object
29 stream1.Position = 0
30 Dim p2 As Person = DirectCast(ser.ReadObject(stream1), Person)
32 'Show the results
33 Console.Write("Deserialized back, got name=")
34 Console.Write(p2.name)
35 Console.Write(", age=")
36 Console.WriteLine(p2.age)
38 Console.WriteLine("Press <ENTER> to terminate the program.")
39 Console.ReadLine()
40 End Sub
41 End Class
43 <DataContract()> _
44 Friend Class Person
45 <DataMember()> _
46 Friend name As String
48 <DataMember()> _
49 Friend age As Integer
50 End Class
52 End Namespace