C# Implementation

suggest change

Before reading the code, it helps to understand the terms used when an application exchanges JSON.

Serialization: converting an object into JSON text that another application can read. The class below can be serialized to JSON.

Deserialization: converting JSON text back into an object. It is the reverse of serialization.

Turn the JSON structure into classes before you serialize or deserialize. In Visual Studio you can paste JSON as classes with Edit > Paste Special > Paste JSON as Classes.

using Newtonsoft.Json;

class Author
{
  [JsonProperty("id")] // Set the variable below to represent the json attribute 
  public int id;       //"id"
  [JsonProperty("name")]
  public string name;
  [JsonProperty("type")]
  public string type;
  [JsonProperty("books")]
  public Book[] books;

  public Author(int id, string name, string type, Book[] books) {
      this.id = id;
      this.name = name;
      this.type= type;
      this.books = books;
  }
}

class Book
{
 [JsonProperty("name")]
 public string name;
 [JsonProperty("date")]
 public DateTime date;
}

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents