Last active
August 12, 2020 01:12
-
-
Save TheEpicFace007/cc0566b2a0fc29f692b45a6a0a17269b to your computer and use it in GitHub Desktop.
Desirilize something with newtonsoft json
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; | |
namespace JSONExample | |
{ | |
internal class Program | |
{ | |
public static void main(string[] args) | |
{ | |
Product product = new Product(); | |
product.Name = "Apple"; | |
product.ExpiryDate = new DateTime(2008, 12, 28); | |
product.Price = 3.99M; | |
product.Sizes = new string[] { "Small", "Medium", "Large" }; | |
// C# -> json | |
string output = JsonConvert.SerializeObject(product); | |
//{ | |
// "Name": "Apple", | |
// "ExpiryDate": "2008-12-28T00:00:00", | |
// "Price": 3.99, | |
// "Sizes": [ | |
// "Small", | |
// "Medium", | |
// "Large" | |
// ] | |
//} | |
/* | |
JSON -> C# | |
you must have a class existing | |
*/ | |
Product deserializedProduct = JsonConvert.DeserializeObject<Product>(output); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment