views:

3469

answers:

4

I need to pass back a JSON result for a routine I am working with. How can I encode an Array I created to JSON? I am writing this in VB.net

+3  A: 
Dim serializer as New JavaScriptSerializer()
Dim arrayJson as String = serializer.Serialize(myArray)
bdukes
+1  A: 

You are going to want to look into JSON serialization. Here is a good article that explains one way to do it (unfortunately the examples are in C#) but with more information we can probalby steer you towards the right toolkit.

Andrew Hare
+4  A: 

There are four ways:

  1. Roll your own with a Custom formatter
  2. Json.NET.
  3. JavaScriptSerializer
  4. DataContractJsonSerializer

I recently blogged about how to do Json Serialization.

I've used Json.NET with much success, it's quite nice.
Matt Olenik
The code that bdukes post did the trick. I will look into your 4 suggestions as well though. Thanks!
Bruno43
bdukes is the one I actually recommend. It's item #3 in the list.
A: 

you could try the javascript serializer (http://msdn.microsoft.com/en-us/library/system.web.script.serialization.javascriptserializer.aspx) I believe it was deprecated for a while by Microsoft but then un-deprecated (is that a word??) when they wanted to use it in MVC

Pharabus