diff --git a/LibreHardwareMonitor/LibreHardwareMonitor.csproj b/LibreHardwareMonitor/LibreHardwareMonitor.csproj index bc3a6ef..2976d9d 100644 --- a/LibreHardwareMonitor/LibreHardwareMonitor.csproj +++ b/LibreHardwareMonitor/LibreHardwareMonitor.csproj @@ -25,7 +25,7 @@ none - + diff --git a/LibreHardwareMonitor/Utilities/HttpServer.cs b/LibreHardwareMonitor/Utilities/HttpServer.cs index 8788c64..c8f5d04 100644 --- a/LibreHardwareMonitor/Utilities/HttpServer.cs +++ b/LibreHardwareMonitor/Utilities/HttpServer.cs @@ -21,7 +21,6 @@ using System.Threading; using System.Web; using LibreHardwareMonitor.Hardware; using LibreHardwareMonitor.UI; -using Newtonsoft.Json.Linq; namespace LibreHardwareMonitor.Utilities; @@ -228,7 +227,7 @@ public class HttpServer //{"result":"fail","message":"Some error message"} //or: //{"result":"ok"} - private void HandleSensorRequest(HttpListenerRequest request, JObject result) + private void HandleSensorRequest(HttpListenerRequest request, Dictionary result) { IDictionary dict = ToDictionary(HttpUtility.ParseQueryString(request.Url.Query)); @@ -283,7 +282,7 @@ public class HttpServer //Currently the only supported base URL is http://localhost:8085/Sensor. private string HandlePostRequest(HttpListenerRequest request) { - JObject result = new() { ["result"] = "ok" }; + var result = new Dictionary { ["result"] = "ok" }; try { @@ -306,11 +305,7 @@ public class HttpServer result["result"] = "fail"; result["message"] = e.ToString(); } -#if DEBUG - return result.ToString(Newtonsoft.Json.Formatting.Indented); -#else - return result.ToString(Newtonsoft.Json.Formatting.None); -#endif + return System.Text.Json.JsonSerializer.Serialize(result); } private void ListenerCallback(IAsyncResult result) @@ -391,7 +386,7 @@ public class HttpServer if (requestedFile.Contains("Sensor")) { - JObject sensorResult = new(); + var sensorResult = new Dictionary(); HandleSensorRequest(request, sensorResult); SendJsonSensor(context.Response, sensorResult); return; @@ -537,7 +532,7 @@ public class HttpServer private void SendJson(HttpListenerResponse response, HttpListenerRequest request = null) { - JObject json = new(); + Dictionary json = new(); int nodeIndex = 0; @@ -548,14 +543,9 @@ public class HttpServer json["Max"] = "Max"; json["ImageURL"] = string.Empty; - json["Children"] = new JArray { GenerateJsonForNode(_root, ref nodeIndex) }; + json["Children"] = new List { GenerateJsonForNode(_root, ref nodeIndex) }; -#if DEBUG - string responseContent = json.ToString(Newtonsoft.Json.Formatting.Indented); -#else - string responseContent = json.ToString(Newtonsoft.Json.Formatting.None); -#endif - byte[] buffer = Encoding.UTF8.GetBytes(responseContent); + byte[] buffer = Encoding.UTF8.GetBytes(System.Text.Json.JsonSerializer.Serialize(json)); bool acceptGzip; try @@ -595,10 +585,10 @@ public class HttpServer response.Close(); } - private void SendJsonSensor(HttpListenerResponse response, JObject sensorData) + private void SendJsonSensor(HttpListenerResponse response, Dictionary sensorData) { // Convert the JObject to a JSON string - string responseContent = sensorData.ToString(Newtonsoft.Json.Formatting.None); + string responseContent = System.Text.Json.JsonSerializer.Serialize(sensorData); byte[] buffer = Encoding.UTF8.GetBytes(responseContent); // Add headers and set content type @@ -621,11 +611,11 @@ public class HttpServer response.Close(); } - private JObject GenerateJsonForNode(Node n, ref int nodeIndex) + private Dictionary GenerateJsonForNode(Node n, ref int nodeIndex) { - JObject jsonNode = new() + Dictionary jsonNode = new() { - ["Id"] = nodeIndex++, + ["id"] = nodeIndex++, ["Text"] = n.Text, ["Min"] = string.Empty, ["Value"] = string.Empty, @@ -654,7 +644,7 @@ public class HttpServer break; } - JArray children = []; + List children = new(); foreach (Node child in n.Nodes) { children.Add(GenerateJsonForNode(child, ref nodeIndex));