技术支持
好物推荐

Vb.net序列化和反序列化json之JavaScriptSerializer对象

很多都是用Newtonsoft.Json,这次记录一下.net framework自带的方法。JavaScriptSerializer对象,需要先引用System.Web.Extensions.dll

Imports System.Web.Script.Serialization

Public Class _Default
    Inherits Page

Public Class Person  'peson类
    Public Property PersonID As Integer
    Public Property Name As String
    Public Property Registered As Boolean
End Class



    Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
        Dim RegisteredUsers As New List(Of Person)()
        RegisteredUsers.Add(New Person With {.PersonID = 1, .Name = "Bryon Hetrick", .Registered = True})
        RegisteredUsers.Add(New Person With {.PersonID = 2, .Name = "Nicole Wilcox", .Registered = True})
        RegisteredUsers.Add(New Person With {.PersonID = 3, .Name = "Adrian Martinson", .Registered = False})
        RegisteredUsers.Add(New Person With {.PersonID = 4, .Name = "Nora Osborn", .Registered = False})

        Dim serializer As New JavaScriptSerializer()
        Dim serializedResult = serializer.Serialize(RegisteredUsers)
        ' 返回如下json字符串
        ' [
        '     {"PersonID":1,"Name":"Bryon Hetrick","Registered":true},
        '     {"PersonID":2,"Name":"Nicole Wilcox","Registered":true},
        '     {"PersonID":3,"Name":"Adrian Martinson","Registered":false},
        '     {"PersonID":4,"Name":"Nora Osborn","Registered":false}
        ' ]

        Dim deserializedResult = serializer.Deserialize(Of List(Of Person))(serializedResult)
        '返回peson类的list
    End Sub
End Class



微信扫描下方的二维码阅读本文

未经允许不得转载:桔子雨 » Vb.net序列化和反序列化json之JavaScriptSerializer对象
分享到: 生成海报
一个数字化服务提供商

承接外贸建站,工具软件,行业软件定制

部分产品联系我们
切换注册

登录

忘记密码 ?

您也可以使用第三方帐号快捷登录

切换登录

注册

微信扫一扫关注
如已关注,请回复“登录”二字获取验证码