1

I'm new to asp.net and visual basic.

I have an assigment where I must send queries to the database and the returns data. I would like to convert that data to a json and then use it with jQuery

My idea is make an array (arrayList?) and then convert it to json.

How can i use json with asp.net vb? I'm not allowed to use a webservice yet


I forgot to mention that this would be a new module in DNN

1
  • Use any of the libraries discussed in this question. Commented Mar 15, 2012 at 22:15

2 Answers 2

2

I wouldn't use an ArrayList, but have a look at the JavaScriptSerializer class.

Sign up to request clarification or add additional context in comments.

Comments

2

You can use the JsonSerializer class to do so

Here is an example creating a list of string objects and converting to json

Dim lstString As New List(Of [String])()
lstString.Add("One")
lstString.Add("Two")

Dim serializer As New JavaScriptSerializer()
Return serializer.Serialize(lstString)

Put this method in an ashx handler and you can access that from jQuery using the getJSON method.

http://api.jquery.com/jQuery.getJSON/

JavaScriptSerializerclass is available in the System.Web.Script.Serialization namespace.

http://msdn.microsoft.com/en-us/library/system.web.script.serialization.javascriptserializer.aspx

You may probably convert it to an extension method like this and use it wherever you want

2 Comments

Thanks. It worked good. It returns an array, what if i want an object? Also, how can make it multidimensional? Like var[0][3] or var.item.name; var.item.color; ???
what object ? you can send your object data as json and in the client you can access that.use the object inside the serialize method and you will get the json for that/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.