diff --git a/Source/Meadow.Foundation.Libraries_and_Frameworks/Serialization.MicroJson/Samples/MicroJson_Complex_Sample/MicroJson_Complex_Sample.csproj b/Source/Meadow.Foundation.Libraries_and_Frameworks/Serialization.MicroJson/Samples/MicroJson_Complex_Sample/MicroJson_Complex_Sample.csproj new file mode 100644 index 0000000000..cf5ff6cc19 --- /dev/null +++ b/Source/Meadow.Foundation.Libraries_and_Frameworks/Serialization.MicroJson/Samples/MicroJson_Complex_Sample/MicroJson_Complex_Sample.csproj @@ -0,0 +1,21 @@ + + + + Exe + net8.0 + enable + + + + + + + + + + + + + + + diff --git a/Source/Meadow.Foundation.Libraries_and_Frameworks/Serialization.MicroJson/Samples/MicroJson_Complex_Sample/Program.cs b/Source/Meadow.Foundation.Libraries_and_Frameworks/Serialization.MicroJson/Samples/MicroJson_Complex_Sample/Program.cs new file mode 100644 index 0000000000..1e0ec3a93b --- /dev/null +++ b/Source/Meadow.Foundation.Libraries_and_Frameworks/Serialization.MicroJson/Samples/MicroJson_Complex_Sample/Program.cs @@ -0,0 +1,33 @@ +using Meadow.Foundation.Serialization; +using System; +using System.IO; +using System.Reflection; +using WifiWeather.DTOs; + +namespace MicroJson_Complex_Sample; + +internal class Program +{ + static void Main(string[] args) + { + Console.WriteLine("Hello, MicroJson - Complex Json"); + + var jsonData = LoadResource("weather.json"); + + var weather = MicroJson.Deserialize(jsonData); + + Console.WriteLine($"Temperature is: {weather.main.temp - 273.15:N1}C"); + } + + static byte[] LoadResource(string filename) + { + var assembly = Assembly.GetExecutingAssembly(); + var resourceName = $"MicroJson_Complex_Sample.{filename}"; + + using Stream stream = assembly.GetManifestResourceStream(resourceName); + using var ms = new MemoryStream(); + + stream?.CopyTo(ms); + return ms.ToArray(); + } +} \ No newline at end of file diff --git a/Source/Meadow.Foundation.Libraries_and_Frameworks/Serialization.MicroJson/Samples/MicroJson_Complex_Sample/WeatherReadingDTO.cs b/Source/Meadow.Foundation.Libraries_and_Frameworks/Serialization.MicroJson/Samples/MicroJson_Complex_Sample/WeatherReadingDTO.cs new file mode 100644 index 0000000000..9a9fc40d89 --- /dev/null +++ b/Source/Meadow.Foundation.Libraries_and_Frameworks/Serialization.MicroJson/Samples/MicroJson_Complex_Sample/WeatherReadingDTO.cs @@ -0,0 +1,63 @@ +namespace WifiWeather.DTOs +{ + public class WeatherReadingDTO + { + public Coordinates coord { get; set; } + public Weather[] weather { get; set; } + public WeatherValues main { get; set; } + public int visibility { get; set; } + public Wind wind { get; set; } + public Clouds clouds { get; set; } + public int dt { get; set; } + public System sys { get; set; } + public long timezone { get; set; } + public int id { get; set; } + public string name { get; set; } + public int cod { get; set; } + } + + public class Coordinates + { + public double lon { get; set; } + public double lat { get; set; } + } + + public class Weather + { + public int id { get; set; } + public string nain { get; set; } + public string description { get; set; } + public string icon { get; set; } + } + + public class WeatherValues + { + public double temp { get; set; } + public double feels_like { get; set; } + public double temp_min { get; set; } + public double temp_max { get; set; } + public int pressure { get; set; } + public int humidity { get; set; } + } + + public class Wind + { + public decimal speed { get; set; } + public int deg { get; set; } + public double gust { get; set; } + } + + public class Clouds + { + public int all { get; set; } + } + + public class System + { + public int Type { get; set; } + public int Id { get; set; } + public string country { get; set; } + public long sunrise { get; set; } + public long sunset { get; set; } + } +} \ No newline at end of file diff --git a/Source/Meadow.Foundation.Libraries_and_Frameworks/Serialization.MicroJson/Samples/MicroJson_Complex_Sample/weather.json b/Source/Meadow.Foundation.Libraries_and_Frameworks/Serialization.MicroJson/Samples/MicroJson_Complex_Sample/weather.json new file mode 100644 index 0000000000..8d6cebfcd0 --- /dev/null +++ b/Source/Meadow.Foundation.Libraries_and_Frameworks/Serialization.MicroJson/Samples/MicroJson_Complex_Sample/weather.json @@ -0,0 +1,43 @@ +{ + "coord": { + "lon": -123.1193, + "lat": 49.2497 + }, + "weather": [ + { + "id": 803, + "main": "Clouds", + "description": "broken clouds", + "icon": "04d" + } + ], + "base": "stations", + "main": { + "temp": 279.01, + "feels_like": 276, + "temp_min": 277.58, + "temp_max": 279.94, + "pressure": 1028, + "humidity": 84 + }, + "visibility": 10000, + "wind": { + "speed": 4.12, + "deg": 90 + }, + "clouds": { + "all": 75 + }, + "dt": 1710347018, + "sys": { + "type": 2, + "id": 2011597, + "country": "CA", + "sunrise": 1710340135, + "sunset": 1710382486 + }, + "timezone": -25200, + "id": 6173331, + "name": "Vancouver", + "cod": 200 +} \ No newline at end of file diff --git a/Source/Meadow.Foundation.sln b/Source/Meadow.Foundation.sln index b61e46705d..5038a4dd75 100644 --- a/Source/Meadow.Foundation.sln +++ b/Source/Meadow.Foundation.sln @@ -1479,6 +1479,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MicroJson_Sample", "Meadow. EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MicroJson_ArrayList_Sample", "Meadow.Foundation.Libraries_and_Frameworks\Serialization.MicroJson\Samples\MicroJson_ArrayList_Sample\MicroJson_ArrayList_Sample.csproj", "{9F5DD1C6-4A3E-4170-BE18-3FAC3A1E0D48}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MicroJson_Complex_Sample", "Meadow.Foundation.Libraries_and_Frameworks\Serialization.MicroJson\Samples\MicroJson_Complex_Sample\MicroJson_Complex_Sample.csproj", "{6FD1D41A-1A80-4E04-B7FF-5EDCE6A526AC}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -3567,6 +3569,10 @@ Global {9F5DD1C6-4A3E-4170-BE18-3FAC3A1E0D48}.Debug|Any CPU.Build.0 = Debug|Any CPU {9F5DD1C6-4A3E-4170-BE18-3FAC3A1E0D48}.Release|Any CPU.ActiveCfg = Release|Any CPU {9F5DD1C6-4A3E-4170-BE18-3FAC3A1E0D48}.Release|Any CPU.Build.0 = Release|Any CPU + {6FD1D41A-1A80-4E04-B7FF-5EDCE6A526AC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {6FD1D41A-1A80-4E04-B7FF-5EDCE6A526AC}.Debug|Any CPU.Build.0 = Debug|Any CPU + {6FD1D41A-1A80-4E04-B7FF-5EDCE6A526AC}.Release|Any CPU.ActiveCfg = Release|Any CPU + {6FD1D41A-1A80-4E04-B7FF-5EDCE6A526AC}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -4305,6 +4311,7 @@ Global {CA32D6C5-DD19-4787-8EE1-B92415FEF903} = {B9C2605C-AC98-4BF1-8E3F-8F0F23A694C9} {5F905795-94F9-43F3-A3F8-AD667C55A730} = {CA32D6C5-DD19-4787-8EE1-B92415FEF903} {9F5DD1C6-4A3E-4170-BE18-3FAC3A1E0D48} = {CA32D6C5-DD19-4787-8EE1-B92415FEF903} + {6FD1D41A-1A80-4E04-B7FF-5EDCE6A526AC} = {CA32D6C5-DD19-4787-8EE1-B92415FEF903} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {AF7CA16F-8C38-4546-87A2-5DAAF58A1520}