SafeDispatch/SafeMobileLIB_DLL/WebsocketClient/WebSocketFormatter.cs
2024-02-22 18:43:59 +02:00

34 lines
893 B
C#

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;
}
}
}