「VB.net」オブジェクトをJSONにするサンプル

書式
JsonConvert.SerializeObject(変数名)
サンプルコード

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
Imports Newtonsoft.Json
Module ModuleTest
Public Class User
Public Property uid As Integer
Public Property name As String
'配列
Public Property info As String()
End Class
Sub Main()
Dim tt As User = New User()
tt.uid = 322
tt.name = "user001"
tt.info = {"AA01", "BB02","CC03"}
'オブジェクトをJSON
Dim resJson As String = JsonConvert.SerializeObject(tt)
Console.WriteLine(resJson)
End Sub
End Module
Imports Newtonsoft.Json Module ModuleTest Public Class User Public Property uid As Integer Public Property name As String '配列 Public Property info As String() End Class Sub Main() Dim tt As User = New User() tt.uid = 322 tt.name = "user001" tt.info = {"AA01", "BB02","CC03"} 'オブジェクトをJSON Dim resJson As String = JsonConvert.SerializeObject(tt) Console.WriteLine(resJson) End Sub End Module
Imports Newtonsoft.Json

Module ModuleTest
      Public Class User
            Public Property uid As Integer
            Public Property name As String
            '配列
            Public Property info As String()
      End Class
      Sub Main()
            Dim tt As User = New User()
            tt.uid = 322
            tt.name = "user001"
            tt.info = {"AA01", "BB02","CC03"}
            
            'オブジェクトをJSON
            Dim resJson As String = JsonConvert.SerializeObject(tt)
            Console.WriteLine(resJson)
      End Sub
End Module

 

VB.net

Posted by arkgame