SafeDispatch/SafeMobileLIB_DLL/WebsocketClient/WebSocketFormatter.cs

34 lines
893 B
C#
Raw Permalink Normal View History

2024-02-22 16:43:59 +00:00
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
namespace SafeMobileLib.WebsocketClient
{
public class WebSocketFormatter
{
public static String ToJson(List<UnitDataToSend> positions)
{
JObject o = new JObject();
try
{
JArray array = new JArray();
for (int i = 0; i < positions.Count; i++)
{
array.Add(JToken.FromObject(positions[i]));
}
o["data"] = array;
}
catch(Exception ex)
{
Console.WriteLine("WebSocketFormatter ToJson Exception: " + ex.ToString());
}
String json = JsonConvert.SerializeObject(o, Formatting.None);
//return o.ToString();
return json;
}
}
}