From a48ad27b1ef217b1fe366e0bd42e7f67c7519ffb Mon Sep 17 00:00:00 2001 From: Alexey Nesterov Date: Fri, 19 Apr 2024 10:28:41 +1000 Subject: [PATCH 1/3] Changed Newtonsoft to System.Text.Json.Serialization --- .../AdamController.Services.csproj | 1 - .../AdamBlocklyLibrary.csproj | 3 --- .../AdamBlocklyLibrary/Enum/BlocklyTheme.cs | 6 ++--- .../AdamBlocklyLibrary/Enum/CategoryStyle.cs | 6 ++--- Legacy/AdamBlocklyLibrary/Enum/Render.cs | 6 ++--- Legacy/AdamBlocklyLibrary/Scripts.cs | 11 +++++--- .../Toolbox/CategoryToolbox.cs | 26 ++++++++++++------- .../Toolbox/SimpleToolbox.cs | 6 ++--- Legacy/AdamBlocklyLibrary/Toolbox/Toolbox.cs | 8 +++--- .../Views/ScratchControlView.xaml.cs | 1 + 10 files changed, 42 insertions(+), 32 deletions(-) diff --git a/AdamController.Services/AdamController.Services.csproj b/AdamController.Services/AdamController.Services.csproj index d25918a..1d184a5 100644 --- a/AdamController.Services/AdamController.Services.csproj +++ b/AdamController.Services/AdamController.Services.csproj @@ -15,7 +15,6 @@ - diff --git a/Legacy/AdamBlocklyLibrary/AdamBlocklyLibrary.csproj b/Legacy/AdamBlocklyLibrary/AdamBlocklyLibrary.csproj index a1d44e5..11d4c2d 100644 --- a/Legacy/AdamBlocklyLibrary/AdamBlocklyLibrary.csproj +++ b/Legacy/AdamBlocklyLibrary/AdamBlocklyLibrary.csproj @@ -47,7 +47,4 @@ Resources.Designer.cs - - - \ No newline at end of file diff --git a/Legacy/AdamBlocklyLibrary/Enum/BlocklyTheme.cs b/Legacy/AdamBlocklyLibrary/Enum/BlocklyTheme.cs index b6f596d..01c26e4 100644 --- a/Legacy/AdamBlocklyLibrary/Enum/BlocklyTheme.cs +++ b/Legacy/AdamBlocklyLibrary/Enum/BlocklyTheme.cs @@ -1,9 +1,9 @@ -using Newtonsoft.Json; -using Newtonsoft.Json.Converters; +using System.Text.Json.Serialization; namespace AdamBlocklyLibrary.Enum { - [JsonConverter(typeof(StringEnumConverter))] + //[JsonConverter(typeof(StringEnumConverter))] + [JsonConverter(typeof(JsonStringEnumConverter))] public enum BlocklyTheme { Classic, diff --git a/Legacy/AdamBlocklyLibrary/Enum/CategoryStyle.cs b/Legacy/AdamBlocklyLibrary/Enum/CategoryStyle.cs index 74b0f75..bb17654 100644 --- a/Legacy/AdamBlocklyLibrary/Enum/CategoryStyle.cs +++ b/Legacy/AdamBlocklyLibrary/Enum/CategoryStyle.cs @@ -1,9 +1,9 @@ -using Newtonsoft.Json; -using Newtonsoft.Json.Converters; +using System.Text.Json.Serialization; namespace AdamBlocklyLibrary.Enum { - [JsonConverter(typeof(StringEnumConverter))] + //[JsonConverter(typeof(StringEnumConverter))] + [JsonConverter(typeof(JsonStringEnumConverter))] public enum CategoryStyle { colour_category, diff --git a/Legacy/AdamBlocklyLibrary/Enum/Render.cs b/Legacy/AdamBlocklyLibrary/Enum/Render.cs index b87dc3a..6932025 100644 --- a/Legacy/AdamBlocklyLibrary/Enum/Render.cs +++ b/Legacy/AdamBlocklyLibrary/Enum/Render.cs @@ -1,9 +1,9 @@ -using Newtonsoft.Json; -using Newtonsoft.Json.Converters; +using System.Text.Json.Serialization; namespace AdamBlocklyLibrary.Enum { - [JsonConverter(typeof(StringEnumConverter))] + //[JsonConverter(typeof(StringEnumConverter))] + [JsonConverter(typeof(JsonStringEnumConverter))] public enum Render { geras, diff --git a/Legacy/AdamBlocklyLibrary/Scripts.cs b/Legacy/AdamBlocklyLibrary/Scripts.cs index 38ee836..ac5d477 100644 --- a/Legacy/AdamBlocklyLibrary/Scripts.cs +++ b/Legacy/AdamBlocklyLibrary/Scripts.cs @@ -1,4 +1,4 @@ -using Newtonsoft.Json; +using System.Text.Json; namespace AdamBlocklyLibrary { @@ -56,7 +56,9 @@ public static string SerealizeObjectToJsonString(string functionName, params obj string script = functionName + "('"; for (int i = 0; i < parameters.Length; i++) { - script += JsonConvert.SerializeObject(parameters[i]); + var options = new JsonSerializerOptions { WriteIndented = true }; + script += JsonSerializer.Serialize(parameters[i]); + //script += JsonConvert.SerializeObject(parameters[i]); if (i < parameters.Length - 1) { script += ", "; @@ -72,7 +74,10 @@ public static string SerealizeObject(string functionName, params object[] parame string script = functionName + "("; for (int i = 0; i < parameters.Length; i++) { - script += JsonConvert.SerializeObject(parameters[i]); + + var options = new JsonSerializerOptions { WriteIndented = true }; + script += JsonSerializer.Serialize(parameters[i]); + //script += JsonConvert.SerializeObject(parameters[i]); if (i < parameters.Length - 1) { script += ", "; diff --git a/Legacy/AdamBlocklyLibrary/Toolbox/CategoryToolbox.cs b/Legacy/AdamBlocklyLibrary/Toolbox/CategoryToolbox.cs index 00b08e1..b7c34dd 100644 --- a/Legacy/AdamBlocklyLibrary/Toolbox/CategoryToolbox.cs +++ b/Legacy/AdamBlocklyLibrary/Toolbox/CategoryToolbox.cs @@ -1,33 +1,38 @@  using AdamBlocklyLibrary.Enum; -using Newtonsoft.Json; using System; using System.Collections.Generic; +using System.Text.Json.Serialization; namespace AdamBlocklyLibrary.Toolbox { public class CategoryToolbox { - [JsonProperty("kind")] + //[JsonProperty("kind")] + [JsonPropertyName("kind")] public string Kind { get; } = "category"; /// /// Name toolbox /// - [JsonProperty("name")] + //[JsonProperty("name")] + [JsonPropertyName("name")] public string Name { get; set; } - [JsonProperty("toolboxitemid")] + //[JsonProperty("toolboxitemid")] + [JsonPropertyName("toolboxitemid")] internal string ToolboxItemId => Guid.NewGuid().ToString(); - [JsonProperty("categorystyle")] + //[JsonProperty("categorystyle")] + [JsonPropertyName("categorystyle")] public CategoryStyle CategoryStyle { get; set; } /// /// For set contents use or . /// If is given, then in will not be serialized /// - [JsonProperty("contents")] + //[JsonProperty("contents")] + [JsonPropertyName("contents")] public object Contents => CategoryToolboxContents ?? (object)SimpleToolboxContents; /// @@ -47,7 +52,8 @@ public class CategoryToolbox /// Note the British spelling. The colour is a number (0-360) defining the hue /// By default categry null, is visible without color /// - [JsonProperty("colour")] + //[JsonProperty("colour")] + [JsonPropertyName("colour")] public string Colour { get; set; } = null; /// @@ -60,7 +66,8 @@ public class CategoryToolbox /// /// For set ExpandedCategory use Expanded /// - [JsonProperty("expanded")] + //[JsonProperty("expanded")] + [JsonPropertyName("expanded")] internal string ExpandedCategory => Expanded ? Expanded.ToString().ToLower() : null; /// @@ -72,7 +79,8 @@ public class CategoryToolbox /// /// For set HiddenCategory use Hidden /// - [JsonProperty("hidden")] + //[JsonProperty("hidden")] + [JsonPropertyName("hidden")] internal string HiddenCategory => Hidden.ToString().ToLower(); } diff --git a/Legacy/AdamBlocklyLibrary/Toolbox/SimpleToolbox.cs b/Legacy/AdamBlocklyLibrary/Toolbox/SimpleToolbox.cs index d5034db..738de5a 100644 --- a/Legacy/AdamBlocklyLibrary/Toolbox/SimpleToolbox.cs +++ b/Legacy/AdamBlocklyLibrary/Toolbox/SimpleToolbox.cs @@ -1,17 +1,17 @@ using AdamBlocklyLibrary.Enum; -using Newtonsoft.Json; +using System.Text.Json.Serialization; namespace AdamBlocklyLibrary.Toolbox { public class SimpleToolbox { - [JsonProperty("kind")] + [JsonPropertyName("kind")] public string Kind { get; } = "block"; [JsonIgnore] public BlockType Type { get; set; } - [JsonProperty("type")] + [JsonPropertyName("type")] public string TypeString => Type.ToString(); } } diff --git a/Legacy/AdamBlocklyLibrary/Toolbox/Toolbox.cs b/Legacy/AdamBlocklyLibrary/Toolbox/Toolbox.cs index d721cee..7c468ff 100644 --- a/Legacy/AdamBlocklyLibrary/Toolbox/Toolbox.cs +++ b/Legacy/AdamBlocklyLibrary/Toolbox/Toolbox.cs @@ -1,18 +1,18 @@ -using Newtonsoft.Json; -using System.Collections.Generic; +using System.Collections.Generic; +using System.Text.Json.Serialization; namespace AdamBlocklyLibrary.Toolbox { public class Toolbox { - [JsonProperty("kind")] + [JsonPropertyName("kind")] public string Kind { get; private set; } = "categoryToolbox"; /// /// For set contents use or . /// If is given, then in will not be serialized /// - [JsonProperty("contents")] + [JsonPropertyName("contents")] internal object Contents => CategoryToolboxContents ?? (object)SimpleToolboxContents; /// diff --git a/Modules/AdamController.Modules.ContentRegion/Views/ScratchControlView.xaml.cs b/Modules/AdamController.Modules.ContentRegion/Views/ScratchControlView.xaml.cs index c79de2f..1b80c36 100644 --- a/Modules/AdamController.Modules.ContentRegion/Views/ScratchControlView.xaml.cs +++ b/Modules/AdamController.Modules.ContentRegion/Views/ScratchControlView.xaml.cs @@ -75,6 +75,7 @@ private void WebViewCoreWebView2InitializationCompleted(object sender, CoreWebVi WebView.CoreWebView2.Settings.AreDevToolsEnabled = true; WebView.CoreWebView2.Settings.AreDefaultContextMenusEnabled = !Settings.Default.DontShowBrowserMenuInBlockly; WebView.CoreWebView2.Settings.AreHostObjectsAllowed = true; + WebView.CoreWebView2.Settings.IsScriptEnabled = true; WebView.CoreWebView2.SetVirtualHostNameToFolderMapping("localhost", mPathToSource, CoreWebView2HostResourceAccessKind.Allow); WebView.CoreWebView2.Navigate("https://localhost/index.html"); } From 39f41428f21999cd429c2001470d1a11600a8dc7 Mon Sep 17 00:00:00 2001 From: Alexey Nesterov Date: Fri, 19 Apr 2024 11:21:45 +1000 Subject: [PATCH 2/3] Fix blockly load error --- .../WebMessageJsonReceived.cs | 8 ++++---- Legacy/AdamBlocklyLibrary/Toolbox/Toolbox.cs | 2 +- .../Views/ScratchControlView.xaml.cs | 18 +++++++++++++++--- 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/AdamController.Services/WebViewProviderDependency/WebMessageJsonReceived.cs b/AdamController.Services/WebViewProviderDependency/WebMessageJsonReceived.cs index b7132fb..44516d5 100644 --- a/AdamController.Services/WebViewProviderDependency/WebMessageJsonReceived.cs +++ b/AdamController.Services/WebViewProviderDependency/WebMessageJsonReceived.cs @@ -1,14 +1,14 @@ -using Newtonsoft.Json; -using System; +using System; +using System.Text.Json.Serialization; namespace AdamController.Services.WebViewProviderDependency { public class WebMessageJsonReceived : EventArgs { - [JsonProperty("action")] + [JsonPropertyName("action")] public string Action { get; set; } - [JsonProperty("data")] + [JsonPropertyName("data")] public string Data { get; set; } } } diff --git a/Legacy/AdamBlocklyLibrary/Toolbox/Toolbox.cs b/Legacy/AdamBlocklyLibrary/Toolbox/Toolbox.cs index 7c468ff..e7f3b9d 100644 --- a/Legacy/AdamBlocklyLibrary/Toolbox/Toolbox.cs +++ b/Legacy/AdamBlocklyLibrary/Toolbox/Toolbox.cs @@ -13,7 +13,7 @@ public class Toolbox /// If is given, then in will not be serialized /// [JsonPropertyName("contents")] - internal object Contents => CategoryToolboxContents ?? (object)SimpleToolboxContents; + public object Contents => CategoryToolboxContents ?? (object)SimpleToolboxContents; /// /// If is given, then in will not be serialized diff --git a/Modules/AdamController.Modules.ContentRegion/Views/ScratchControlView.xaml.cs b/Modules/AdamController.Modules.ContentRegion/Views/ScratchControlView.xaml.cs index 1b80c36..5ff5bf7 100644 --- a/Modules/AdamController.Modules.ContentRegion/Views/ScratchControlView.xaml.cs +++ b/Modules/AdamController.Modules.ContentRegion/Views/ScratchControlView.xaml.cs @@ -1,12 +1,17 @@  +using AdamBlocklyLibrary; using AdamController.Core.Helpers; using AdamController.Core.Properties; using AdamController.Services.Interfaces; using AdamController.Services.WebViewProviderDependency; +using ImTools; using Microsoft.Web.WebView2.Core; using Newtonsoft.Json; + +//using Newtonsoft.Json; using System; using System.IO; +using System.Text.Json; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; @@ -75,15 +80,22 @@ private void WebViewCoreWebView2InitializationCompleted(object sender, CoreWebVi WebView.CoreWebView2.Settings.AreDevToolsEnabled = true; WebView.CoreWebView2.Settings.AreDefaultContextMenusEnabled = !Settings.Default.DontShowBrowserMenuInBlockly; WebView.CoreWebView2.Settings.AreHostObjectsAllowed = true; - WebView.CoreWebView2.Settings.IsScriptEnabled = true; WebView.CoreWebView2.SetVirtualHostNameToFolderMapping("localhost", mPathToSource, CoreWebView2HostResourceAccessKind.Allow); WebView.CoreWebView2.Navigate("https://localhost/index.html"); } private void WebViewWebMessageReceived(object sender, CoreWebView2WebMessageReceivedEventArgs e) { - dynamic jsonClean = JsonConvert.DeserializeObject(e.WebMessageAsJson); - WebMessageJsonReceived receivedResult = JsonConvert.DeserializeObject(jsonClean); + var options = new JsonSerializerOptions { WriteIndented = true }; + + dynamic jsonClean = System.Text.Json.JsonSerializer.Deserialize(e.WebMessageAsJson, options); + WebMessageJsonReceived receivedResult = System.Text.Json.JsonSerializer.Deserialize(jsonClean); + + //WebMessageJsonReceived receivedResult = JsonConvert.DeserializeObject(e.WebMessageAsJson); + + //dynamic jsonClean = JsonConvert.DeserializeObject(e.WebMessageAsJson); + //WebMessageJsonReceived receivedResult = JsonConvert.DeserializeObject(jsonClean); + if (receivedResult == null) return; mWebViewProvider.WebViewMessageReceived(receivedResult); From a0c98ba30abcb26f1647cc9dd081aaf6f4c14490 Mon Sep 17 00:00:00 2001 From: Alexey Nesterov Date: Fri, 19 Apr 2024 12:40:40 +1000 Subject: [PATCH 3/3] Close #31 p 2 --- .../AdamBlocklyLibrary/Enum/BlocklyTheme.cs | 1 - .../AdamBlocklyLibrary/Enum/CategoryStyle.cs | 1 - Legacy/AdamBlocklyLibrary/Enum/Render.cs | 1 - Legacy/AdamBlocklyLibrary/Scripts.cs | 7 +-- .../Toolbox/CategoryToolbox.cs | 10 +--- .../Views/ScratchControlView.xaml.cs | 46 +++++++++++-------- 6 files changed, 29 insertions(+), 37 deletions(-) diff --git a/Legacy/AdamBlocklyLibrary/Enum/BlocklyTheme.cs b/Legacy/AdamBlocklyLibrary/Enum/BlocklyTheme.cs index 01c26e4..30ad9d4 100644 --- a/Legacy/AdamBlocklyLibrary/Enum/BlocklyTheme.cs +++ b/Legacy/AdamBlocklyLibrary/Enum/BlocklyTheme.cs @@ -2,7 +2,6 @@ namespace AdamBlocklyLibrary.Enum { - //[JsonConverter(typeof(StringEnumConverter))] [JsonConverter(typeof(JsonStringEnumConverter))] public enum BlocklyTheme { diff --git a/Legacy/AdamBlocklyLibrary/Enum/CategoryStyle.cs b/Legacy/AdamBlocklyLibrary/Enum/CategoryStyle.cs index bb17654..ad971be 100644 --- a/Legacy/AdamBlocklyLibrary/Enum/CategoryStyle.cs +++ b/Legacy/AdamBlocklyLibrary/Enum/CategoryStyle.cs @@ -2,7 +2,6 @@ namespace AdamBlocklyLibrary.Enum { - //[JsonConverter(typeof(StringEnumConverter))] [JsonConverter(typeof(JsonStringEnumConverter))] public enum CategoryStyle { diff --git a/Legacy/AdamBlocklyLibrary/Enum/Render.cs b/Legacy/AdamBlocklyLibrary/Enum/Render.cs index 6932025..dd678f7 100644 --- a/Legacy/AdamBlocklyLibrary/Enum/Render.cs +++ b/Legacy/AdamBlocklyLibrary/Enum/Render.cs @@ -2,7 +2,6 @@ namespace AdamBlocklyLibrary.Enum { - //[JsonConverter(typeof(StringEnumConverter))] [JsonConverter(typeof(JsonStringEnumConverter))] public enum Render { diff --git a/Legacy/AdamBlocklyLibrary/Scripts.cs b/Legacy/AdamBlocklyLibrary/Scripts.cs index ac5d477..31df03c 100644 --- a/Legacy/AdamBlocklyLibrary/Scripts.cs +++ b/Legacy/AdamBlocklyLibrary/Scripts.cs @@ -56,9 +56,8 @@ public static string SerealizeObjectToJsonString(string functionName, params obj string script = functionName + "('"; for (int i = 0; i < parameters.Length; i++) { - var options = new JsonSerializerOptions { WriteIndented = true }; script += JsonSerializer.Serialize(parameters[i]); - //script += JsonConvert.SerializeObject(parameters[i]); + if (i < parameters.Length - 1) { script += ", "; @@ -74,10 +73,8 @@ public static string SerealizeObject(string functionName, params object[] parame string script = functionName + "("; for (int i = 0; i < parameters.Length; i++) { - - var options = new JsonSerializerOptions { WriteIndented = true }; script += JsonSerializer.Serialize(parameters[i]); - //script += JsonConvert.SerializeObject(parameters[i]); + if (i < parameters.Length - 1) { script += ", "; diff --git a/Legacy/AdamBlocklyLibrary/Toolbox/CategoryToolbox.cs b/Legacy/AdamBlocklyLibrary/Toolbox/CategoryToolbox.cs index b7c34dd..ef3a72c 100644 --- a/Legacy/AdamBlocklyLibrary/Toolbox/CategoryToolbox.cs +++ b/Legacy/AdamBlocklyLibrary/Toolbox/CategoryToolbox.cs @@ -8,22 +8,18 @@ namespace AdamBlocklyLibrary.Toolbox { public class CategoryToolbox { - //[JsonProperty("kind")] [JsonPropertyName("kind")] public string Kind { get; } = "category"; /// /// Name toolbox /// - //[JsonProperty("name")] [JsonPropertyName("name")] public string Name { get; set; } - //[JsonProperty("toolboxitemid")] [JsonPropertyName("toolboxitemid")] - internal string ToolboxItemId => Guid.NewGuid().ToString(); + public string ToolboxItemId => Guid.NewGuid().ToString(); - //[JsonProperty("categorystyle")] [JsonPropertyName("categorystyle")] public CategoryStyle CategoryStyle { get; set; } @@ -31,7 +27,6 @@ public class CategoryToolbox /// For set contents use or . /// If is given, then in will not be serialized /// - //[JsonProperty("contents")] [JsonPropertyName("contents")] public object Contents => CategoryToolboxContents ?? (object)SimpleToolboxContents; @@ -52,7 +47,6 @@ public class CategoryToolbox /// Note the British spelling. The colour is a number (0-360) defining the hue /// By default categry null, is visible without color /// - //[JsonProperty("colour")] [JsonPropertyName("colour")] public string Colour { get; set; } = null; @@ -66,7 +60,6 @@ public class CategoryToolbox /// /// For set ExpandedCategory use Expanded /// - //[JsonProperty("expanded")] [JsonPropertyName("expanded")] internal string ExpandedCategory => Expanded ? Expanded.ToString().ToLower() : null; @@ -79,7 +72,6 @@ public class CategoryToolbox /// /// For set HiddenCategory use Hidden /// - //[JsonProperty("hidden")] [JsonPropertyName("hidden")] internal string HiddenCategory => Hidden.ToString().ToLower(); diff --git a/Modules/AdamController.Modules.ContentRegion/Views/ScratchControlView.xaml.cs b/Modules/AdamController.Modules.ContentRegion/Views/ScratchControlView.xaml.cs index 5ff5bf7..f51bca2 100644 --- a/Modules/AdamController.Modules.ContentRegion/Views/ScratchControlView.xaml.cs +++ b/Modules/AdamController.Modules.ContentRegion/Views/ScratchControlView.xaml.cs @@ -1,17 +1,13 @@  -using AdamBlocklyLibrary; using AdamController.Core.Helpers; using AdamController.Core.Properties; using AdamController.Services.Interfaces; using AdamController.Services.WebViewProviderDependency; -using ImTools; using Microsoft.Web.WebView2.Core; -using Newtonsoft.Json; - -//using Newtonsoft.Json; using System; using System.IO; using System.Text.Json; +using System.Text.Json.Serialization; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; @@ -24,19 +20,21 @@ public partial class ScratchControlView : UserControl #region Services private readonly IWebViewProvider mWebViewProvider; - + private readonly IStatusBarNotificationDeliveryService mStatusBarNotification; + #endregion private readonly string mPathToSource = Path.Combine(FolderHelper.CommonDirAppData, "BlocklySource"); private readonly string mPath = Path.Combine(Path.GetTempPath(), "AdamBrowser"); - public ScratchControlView(IWebViewProvider webViewProvider) + public ScratchControlView(IWebViewProvider webViewProvider, IStatusBarNotificationDeliveryService statusBarNotification) { InitializeComponent(); InitializeWebViewCore(); mWebViewProvider = webViewProvider; + mStatusBarNotification = statusBarNotification; WebView.CoreWebView2InitializationCompleted += WebViewCoreWebView2InitializationCompleted; WebView.NavigationCompleted += WebViewNavigationCompleted; @@ -77,26 +75,34 @@ private async void InitializeWebViewCore() private void WebViewCoreWebView2InitializationCompleted(object sender, CoreWebView2InitializationCompletedEventArgs e) { - WebView.CoreWebView2.Settings.AreDevToolsEnabled = true; + //unused options? + //WebView.CoreWebView2.Settings.AreDevToolsEnabled = true; + //WebView.CoreWebView2.Settings.AreHostObjectsAllowed = true; + WebView.CoreWebView2.Settings.AreDefaultContextMenusEnabled = !Settings.Default.DontShowBrowserMenuInBlockly; - WebView.CoreWebView2.Settings.AreHostObjectsAllowed = true; WebView.CoreWebView2.SetVirtualHostNameToFolderMapping("localhost", mPathToSource, CoreWebView2HostResourceAccessKind.Allow); WebView.CoreWebView2.Navigate("https://localhost/index.html"); } private void WebViewWebMessageReceived(object sender, CoreWebView2WebMessageReceivedEventArgs e) { - var options = new JsonSerializerOptions { WriteIndented = true }; - - dynamic jsonClean = System.Text.Json.JsonSerializer.Deserialize(e.WebMessageAsJson, options); - WebMessageJsonReceived receivedResult = System.Text.Json.JsonSerializer.Deserialize(jsonClean); - - //WebMessageJsonReceived receivedResult = JsonConvert.DeserializeObject(e.WebMessageAsJson); - - //dynamic jsonClean = JsonConvert.DeserializeObject(e.WebMessageAsJson); - //WebMessageJsonReceived receivedResult = JsonConvert.DeserializeObject(jsonClean); - - if (receivedResult == null) return; + JsonSerializerOptions options = new() + { + NumberHandling = JsonNumberHandling.AllowReadingFromString | JsonNumberHandling.WriteAsString + }; + + WebMessageJsonReceived receivedResult; + + try + { + string receivedString = e.TryGetWebMessageAsString(); + receivedResult = JsonSerializer.Deserialize(receivedString, options); + } + catch + { + mStatusBarNotification.AppLogMessage = "Error reading blokly code"; + receivedResult = new WebMessageJsonReceived { Action = string.Empty, Data = string.Empty }; + } mWebViewProvider.WebViewMessageReceived(receivedResult); }