pixeldev
pixeldev

Reputation: 1513

How can I JSON encode an array in VB.NET?

I need to pass back a JSON result for a routine I am working with. In VB.NET, how can arrays be JSON encoded?

Upvotes: 14

Views: 36022

Answers (4)

Brig Lamoreaux
Brig Lamoreaux

Reputation:

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.

Upvotes: 9

Pharabus
Pharabus

Reputation: 6062

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

Upvotes: 0

Andrew Hare
Andrew Hare

Reputation: 351526

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.

Upvotes: 3

bdukes
bdukes

Reputation: 155935

Dim serializer as New JavaScriptSerializer()
Dim arrayJson as String = serializer.Serialize(myArray)

Upvotes: 22

Related Questions