Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create JSON with .net

Tags:

json

.net

asp.net

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.

like image 641
Till Avatar asked Oct 01 '08 17:10

Till


People also ask

How do I create a JSON file?

Open a Text editor like Notepad, Visual Studio Code, Sublime, or your favorite one. Copy and Paste below JSON data in Text Editor or create your own base on the What is JSON article. Once file data are validated, save the file with the extension of . json, and now you know how to create the Valid JSON document.

Does C# have JSON?

C# JSON serialize Serialize converts the value of a specified type into a JSON string.

What is JSON C#?

JSON (JavaScript Object Notation) is a lightweight data-interchange format. It is language-independent, easy to understand and self-describing. It is used as an alternative to XML. JSON is very popular nowadays. JSON represents objects in structured text format and data stored in key-value pairs.

What is JSON serialization in C#?

Serialization is the process of converting . NET objects such as strings into a JSON format and deserialization is the process of converting JSON data into . NET objects. In this article and code examples, first we will learn how to serialize JSON in C# and then we will learn how to deserialize JSON in C#.


2 Answers

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.

like image 93
John Sheehan Avatar answered Oct 28 '22 21:10

John Sheehan


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

like image 26
bdukes Avatar answered Oct 28 '22 22:10

bdukes