15

First off, let me start off that I am not a .net developer. The reason why I am asking this question is that we rolled out our REST-API and one of our first integration partners is a .net shop.

So basically we assumed that .net would provide some sort of wrapper to create JSON, but the developer in question created the string by hand. I've researched this topic a bit and I couldn't really find anything, though I believe .net provides something. :)

'current code    
Dim data As String
data = "[hello, world]"

In PHP I would do the following (assuming ext/json is available ;):

<?php
$json = array('hello', 'world');
$json = json_encode($json);

I am also interested in what you use to decode the json into an array/object structure.

Help is very appreciated.

spender
  • 117,338
  • 33
  • 229
  • 351
Till
  • 22,236
  • 4
  • 59
  • 89

6 Answers6

15

There are a couple first-party and third-party options. Rick Strahl has a good overview. JSON.net is the most popular third-party option.

John Sheehan
  • 77,456
  • 30
  • 160
  • 194
  • 1
    This looks pretty good. I'll investigate this and will let you know. Thanks so far! (Sorry, I don't have any votes left right now. Regardless of what I'll choose, I will vote for this tomorrow.) – Till Oct 01 '08 at 17:55
10

See Is there a built in way in .Net AJAX to manually serialize an object to a JSON string?

Which is to say, in .NET 2.0,

Dim yourData As String() = { "Hello", "World" }
Dim jsonSerialiser As New System.Web.Script.Serialization.JavaScriptSerializer
Dim jsonString as String = jsonSerialiser.Serialize(yourData)

In .NET 3.5, send them to Rick Strahl's blog, mentioned above

Community
  • 1
  • 1
bdukes
  • 152,002
  • 23
  • 148
  • 175
  • I saw this, it doesn't actually answer my question though. Or maybe I don't get it. – Till Oct 01 '08 at 17:54
7

Json.Net is an easy to use library with some cool features.

Wayne
  • 38,646
  • 4
  • 37
  • 49
3

JavaScriptSerializer is very straight forward.

Person person = new Person();

JavaScriptSerializer serializer = new JavaScriptSerializer();
String json = serializer.Serialize(person);
kd7iwp
  • 3,110
  • 8
  • 30
  • 39
aleemb
  • 31,265
  • 19
  • 98
  • 114
2

I'm with Wayne - JSON.net works well. The nice is, it works well with no learning curve.

David Robbins
  • 9,996
  • 7
  • 51
  • 82
0

Check out DataContractJsonSerializer.

Kevin Hakanson
  • 41,386
  • 23
  • 126
  • 155