The VB. NET Json operation includes nested

Source: Internet
Author: User
Imports System. runtime. serialization. jsonImports System. IOPartial Class _ Default Inherits System. web. UI. page Protected Sub button#click (ByVal sender As Object, ByVal e As System. eventArgs) Handles Button1.Click Dim strTest As String 'strtest = "{" "name": "" Peggy "", "" email "": "" peggy@gmail.com ""} "'button1. attributes. add ("onclick", "json (" & strTest & ")") strTest = "{" "result": [{"" content "": "" Hello "", "" sendPhone ":" 15523565211 "", "" replayTime ":" "09:45:15. 887 "" },{ "" content ":" "" "," "sendPhone": "" 15523565211 "", "" replayTime "": "" 09:42:48. 933 "" },{ "" content ":" "" "," "sendPhone": "" 15523565211 "," "replayTime "": "" 09:34:31. 727 ""}], "" success "": true} "'dim mytest As test' mytest = FromJosnT (Of Test) (strTest) 'response. write (mytest. name & "& mytest. email) Dim myTest As content myTest = FromJosnT (Of content) (strTest) For Each AB As BackContent In myTest. result Response. write (AB. content & AB. sendPhone & AB. replayTime) Next Response. write (myTest. success) End Sub Public Function FromJosn (ByVal josn As String) As Object Dim ds As DataContractJsonSerializer = New DataContractJsonSerializer (GetType (Test) Dim MS As MemoryStream = New MemoryStream (System. text. encoding. UTF8.GetBytes (josn) Return ds. readObject (MS) End Function Public Function ToJosnT (Of T) (ByVal myT As T) As String Dim ds = New DataContractJsonSerializer (GetType (T) Dim MS = New MemoryStream () ds. writeObject (MS, myT) Dim strReturn As String strReturn = Encoding. UTF8.GetString (ms. toArray () ms. close () Return strReturn End Function Public Function FromJosnT (Of T) (ByVal josn As String) As T Dim ds As DataContractJsonSerializer = New DataContractJsonSerializer (GetType (T )) dim MS As MemoryStream = New MemoryStream (System. text. encoding. UTF8.GetBytes (josn) Return ds. readObject (MS) End Function Protected Sub Button2_Click (ByVal sender As Object, ByVal e As System. eventArgs) Handles Button2.Click Dim myTest As New Test () myTest. name = "test" myTest. email = "adfas@163.com" Response. write (ToJosnT (Of Test) (myTest) End SubEnd ClassPublic Class Test Private _ name As String Public Property name As String Get Return _ name End Get Set (ByVal value As String) _ name = value End Set End Property Private _ email As String Public Property email As String Get Return _ email End Get Set (ByVal value As String) _ email = value End Set End PropertyEnd ClassPublic Class BackContent Private _ content As String Public Property content As String Get Return _ content End Get Set (ByVal value As String) _ content = value End Set End Property Private _ sendPhone As String Public Property sendPhone As String Get Return _ sendPhone End Get Set (ByVal value As String) _ sendPhone = value End Set End Property Private _ replayTime As String Public Property replayTime As String Get Return _ replayTime End Get Set (ByVal value As String) _ replayTime = value End Set End PropertyEnd ClassPublic Class content Private _ result As IList (Of BackContent) Public Property result As IList (Of BackContent) get Return _ result End Get Set (ByVal value As IList (Of BackContent )) _ result = value End Set End Property Private _ success As String Public Property success As String Get Return _ success End Get Set (ByVal value As String) _ success = value End Set End PropertyEnd Class

  

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.