json in c# code example

Example 1: c# serialize json

using System.Text.Json;

//Serialize
var jsonString = JsonSerializer.Serialize(yourObject);

// Deserialize
var obj = JsonSerializer.Deserialize<YourObject>(stringValue);

Example 2: json property C#

public class Videogame
{
    [JsonProperty("name")]
    public string Name { get; set; }

    [JsonProperty("release_date")]
    public DateTime ReleaseDate { get; set; }
}

Example 3: how get data from json in c#

public class JSONResponse
{
    public string status { get; set; }
    public List<Article> articles { get; set; }
}


JSONResponse response = JsonConvert.DeserializeObject<JSONResponse>(myJSON);

Example 4: c# create a json object

dynamic ret = new JObject();

ret = new JObject(new JProperty("vendorDetails", new JObject()));

ret.vendorDetails.Add(new JProperty("vendorName", "Vendor Name"));

Tags:

Php Example