Creating a JSON string using json.net in Visual Basic

Employ this facility to produce classes from JSON strings. The API key was eliminated from the code owing to issues with it.

Question:

I am currently employing json.net for analyzing a JSON text and have obtained a

JObject

.

Dim json_text As String
json_text = "{" & Chr(34) & "Venue" & Chr(34) & ": {" & Chr(34) & "ID" & Chr(34) & ":" & Chr(34) & "JSON" & Chr(34) & "}}"
Console.WriteLine(json_text)
Dim json As JObject
json = JObject.Parse(json_text)
Console.WriteLine(json.SelectToken("Venue").SelectToken("ID"))

My aim is to create a JSON text using the JSON variable in a reverse manner.

Regrettably, a viable solution seems to be elusive.


Solution:

    Imports Newtonsoft.Json.Linq
    Imports Newtonsoft.Json
    Dim json_text As String
    json_text = "{" & Chr(34) & "Venue" & Chr(34) & ": {" & Chr(34) & "ID" & Chr(34) & ":" & Chr(34) & "JSON" & Chr(34) & "}}"
    Console.WriteLine(json_text)
    Dim json As JObject
    json = JObject.Parse(json_text)
    Console.WriteLine(json.SelectToken("Venue").SelectToken("ID"))
    Dim json_string As String = JsonConvert.SerializeObject(json,
                   Formatting.Indented, New JsonSerializerSettings())
    Console.WriteLine(json_string)

This results in:

{"Venue": {"ID":"JSON"}}
JSON
{
  "Venue": {
    "ID": "JSON"
  }
}

Frequently Asked Questions