Created
April 15, 2024 15:50
-
-
Save russfeld/e80b68a2a52cbfb1dae5e0d5b35dde8e to your computer and use it in GitHub Desktop.
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 System; | |
using Newtonsoft.Json; | |
String json = "{\"items\": [{\"name\": \"ground pork\", \"calories\": 668.2, \"serving_size_g\": 226.796, \"fat_total_g\": 47.4, \"fat_saturated_g\": 17.7, \"protein_g\": 57.8, \"sodium_mg\": 168, \"potassium_mg\": 508, \"cholesterol_mg\": 210, \"carbohydrates_total_g\": 0.0, \"fiber_g\": 0.0, \"sugar_g\": 0.0}]}"; | |
Recipe_List rec = JsonConvert.DeserializeObject<Recipe_List>(json)!; | |
Console.WriteLine(rec.Items![0].Name); |
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; | |
public class Recipe_JSON | |
{ | |
[JsonProperty("sugar_g")] | |
public double Sugar { get; set; } | |
[JsonProperty("fiber_g")] | |
public double Fiber { get; set; } | |
[JsonProperty("serving_size_g")] | |
public double ServingSize { get; set; } | |
[JsonProperty("sodium_mg")] | |
public double Sodium { get; set; } | |
[JsonProperty("name")] | |
public string? Name { get; set; } | |
[JsonProperty("potassium_mg")] | |
public double Potassium { get; set; } | |
[JsonProperty("fat_saturated_g")] | |
public double SaturatedFat { get; set; } | |
[JsonProperty("fat_total_g")] | |
public double TotalFat { get; set; } | |
[JsonProperty("calories")] | |
public double Calories { get; set; } | |
[JsonProperty("cholesterol_mg")] | |
public double Cholesterol { get; set; } | |
[JsonProperty("protein_g")] | |
public double Protein { get; set; } | |
[JsonProperty("carbohydrates_total_g")] | |
public double Carbs { get; set; } | |
} |
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; | |
public class Recipe_List | |
{ | |
[JsonProperty("items")] | |
public Recipe_JSON[]? Items { get; set; } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment