如何使用vb.net数组创建此 JSON数组 var data = {items: [{value: "21", name: "Mick Jagger"},{value: "43", name: "Johnny Storm"},{value: "46", name: "Richard Hatch"},{value: "54", name: "Kelly Slater"},{value: "55", name: "Rudy Hamil
var data = {items: [ {value: "21", name: "Mick Jagger"}, {value: "43", name: "Johnny Storm"}, {value: "46", name: "Richard Hatch"}, {value: "54", name: "Kelly Slater"}, {value: "55", name: "Rudy Hamilton"}, {value: "79", name: "Michael Jordan"} ]};当您使用.NET 2.0时,您必须使用James的JSON库,并在Codeplex下载(.NET 2.0版本).
使用Json.NET的一个例子
添加对Newtonsoft.Json的引用,并在您的类中添加Import Newtonsoft.Json.
例:
Import Newtonsoft.Json Dim product As New Product() product.Name = "Captopril" product.Expiry = New DateTime(2008, 12, 28) product.Price = 3.99D product.Sizes = New String() {"Small", "Medium", "Large"} 'Call SeralizeObject to convert the object to JSON string' Dim output As String = JavaScriptConvert.SerializeObject(product)
输出变量将保存值:
{ "Name": "Captopril", "Expiry": "\/Date(1230375600000+1300)\/", "Price": 3.99, "Sizes": [ "Small", "Medium", "Large" ] }