VB.net operation josn

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 & ")") dim mytest as test mytest = fromjosnt (of test) (strtest) response. write (mytest. name & "& mytest. email) 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 class

Paste the code first and then sort it out !! Save yourself and forget

  

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.