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
2009-02-23 19:50:27
+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
2009-02-23 19:50:38
+4
A:
There are four ways:
- Roll your own with a Custom formatter
- Json.NET.
- JavaScriptSerializer
- DataContractJsonSerializer
I recently blogged about how to do Json Serialization.
I've used Json.NET with much success, it's quite nice.
Matt Olenik
2009-02-23 19:54:38
The code that bdukes post did the trick. I will look into your 4 suggestions as well though. Thanks!
Bruno43
2009-02-23 20:59:31
bdukes is the one I actually recommend. It's item #3 in the list.
2009-02-24 01:05:49
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
2009-02-23 19:51:01