Created
July 8, 2020 00:29
-
-
Save luisdeol/0dfc0b5c10f40207b42e6af7df99af78 to your computer and use it in GitHub Desktop.
4.2: Consume JSON data.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Newtonsoft.Json; | |
using System; | |
namespace _42_ConsumeData | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
var jsonProduct = "{ \"description\": \"Product 5\", \"quantity\": 500, \"price\": 150.0 }"; | |
var product = JsonConvert.DeserializeObject<Product>(jsonProduct); | |
Console.WriteLine($"Description: {product.Description}, Quantity: {product.Quantity}, Price: {product.Price}"); | |
jsonProduct = JsonConvert.SerializeObject(product); | |
Console.WriteLine(jsonProduct); | |
Console.ReadKey(); | |
} | |
} | |
public class Product | |
{ | |
public string Description { get; set; } | |
public int Quantity { get; set; } | |
public decimal Price { get; set; } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment