Imports Newtonsoft.Json
Imports Newtonsoft.Json.Linq
Public Class JsonUtils
''' <summary>
''' Ctor
''' </summary>
''' <remarks></remarks>
Sub New()
End Sub
''' <summary>
''' it's not a bug.
''' it's a furture.
''' </summary>
''' <returns></returns>
''' <remarks></remarks>
Public Shared Function หอย_งาม() As String
Return "โหนกนูน"
End Function
Public Shared Sub Example_SerializeObject()
Dim prd As Product = New Product()
prd.ProductID = 1
prd.ProductName = "Pencil"
prd.Sizes = {"Small", "Middle"}
Dim json As String = JsonConvert.SerializeObject(prd)
'//{
'// "ProductID ":1,"
'// "ProductName":"Pencil",
'// "Sizes":["Small","Middle"]
'//}
End Sub
Public Shared Sub Example_DeserializeObject()
Dim json = <json>
{
"ProductID ":1,"
"ProductName":"Pencil",
"Sizes":["Small","Middle"]
}
</json>
Dim objProduct As Product = JsonConvert.DeserializeObject(Of Product)(json.ToString().Trim(New Char() {vbLf, vbNewLine, vbTab, vbCrLf, vbCr, " "}))
Dim prdName As String = objProduct.ProductName 'Result Pencil
End Sub
Public Shared Sub Example_Linq2Json()
Dim array As JArray = New JArray() 'Name space Newtonsoft.Json.Linq
array.Add("Banana")
array.Add(New Date(2016, 12, 31))
Dim obj As JObject = New JObject
obj("myArray") = array
Dim json As String = obj.ToString()
'// {
'// "MyArray": [
'// "Banana",
'// "2016-12-31T00:00:00"
'// ]
'// }
End Sub
''' <summary>
''' Demo Class
''' </summary>
''' <remarks></remarks>
Public Class Product
Public Property ProductID As Integer
Public Property ProductName As String
Public Property Sizes As String()
End Class
End Class