I need to pass back a JSON result for a routine I am working with. In VB.NET, how can arrays be JSON encoded?
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
Dim serializer as New JavaScriptSerializer() Dim arrayJson as String = serializer.Serialize(myArray)
Method 2
There are four ways:
- Roll your own with a Custom formatter
- Json.NET.
- JavaScriptSerializer
- DataContractJsonSerializer
I recently blogged about how to do Json Serialization.
Method 3
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.
Method 4
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
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0