using Newtonsoft.Json; using Newtonsoft.Json.Linq; using System; using System.Collections.Generic; namespace SafeMobileLib.WebsocketClient { public class WebSocketFormatter { public static String ToJson(List 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; } } }