diff --git a/Utilities.Rest/Packages/com.utilities.rest/Runtime/Rest.cs b/Utilities.Rest/Packages/com.utilities.rest/Runtime/Rest.cs index 8e9707e..d6f45c1 100644 --- a/Utilities.Rest/Packages/com.utilities.rest/Runtime/Rest.cs +++ b/Utilities.Rest/Packages/com.utilities.rest/Runtime/Rest.cs @@ -1,6 +1,7 @@ // Licensed under the MIT License. See LICENSE in the project root for license information. using Newtonsoft.Json; +using Newtonsoft.Json.Linq; using System; using System.Collections.Generic; using System.IO; @@ -1273,17 +1274,30 @@ void SendServerEventCallback(bool isEnd) return; } - var eventStringBuilder = new StringBuilder(); - eventStringBuilder.Append("{"); - eventStringBuilder.Append($"\"{type}\":\"{value}\""); + var eventObject = new Dictionary(); + + try + { + eventObject[type] = JToken.Parse(value); + } + catch + { + eventObject[type] = value; + } if (!string.IsNullOrWhiteSpace(data)) { - eventStringBuilder.Append($",\"{nameof(data)}\":\"{data}\""); + try + { + eventObject[nameof(data)] = JToken.Parse(data); + } + catch + { + eventObject[nameof(data)] = data; + } } - eventStringBuilder.Append("}"); - serverSentEventCallback.Invoke(eventStringBuilder.ToString()); + serverSentEventCallback.Invoke(JsonConvert.SerializeObject(eventObject)); parameters.ServerSentEventCount++; parameters.ServerSentEvents.Add(new Tuple(type, value, data)); } diff --git a/Utilities.Rest/Packages/com.utilities.rest/package.json b/Utilities.Rest/Packages/com.utilities.rest/package.json index b812386..868b4b7 100644 --- a/Utilities.Rest/Packages/com.utilities.rest/package.json +++ b/Utilities.Rest/Packages/com.utilities.rest/package.json @@ -3,7 +3,7 @@ "displayName": "Utilities.Rest", "description": "This package contains useful RESTful utilities for the Unity Game Engine.", "keywords": [], - "version": "3.0.0", + "version": "3.0.1", "unity": "2021.3", "documentationUrl": "https://github.com/RageAgainstThePixel/com.utilities.rest#documentation", "changelogUrl": "https://github.com/RageAgainstThePixel/com.utilities.rest/releases",