I want to create a json object in vb.net to send the response back javascript function to do something please tell me if anyone have any idea about it.
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.
How to serialize an object (Product is only an example object, change this to your own object):
Dim product As New Product()
product.Name = "Apple"
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": "Apple",
"Expiry": "\/Date(1230375600000+1300)\/",
"Price": 3.99,
"Sizes": [
"Small",
"Medium",
"Large"
]
}
Another example would be to convert an array of strings.
Dim myArray As String() = {"Hello", "World"}
Dim jsonString As String = JavaScriptConvert.SerializeObject(myArray)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With