Json – How to create JSON array using vb.net


How to create this JSON array using vb.net array

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"}

Best Solution

As you're using .NET 2.0 you have to use the JSON libary by James, with download at Codeplex (version for .NET 2.0).

An example of using Json.NET

Add a reference to Newtonsoft.Json, and an Import Newtonsoft.Json in your class.


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)

The output variable will hold the value:

  "Name": "Captopril",
  "Expiry": "\/Date(1230375600000+1300)\/",
  "Price": 3.99,
  "Sizes": [