diff --git a/Groot/Groot.cs b/Groot/Groot.cs index 7d917b9..3c1592e 100644 --- a/Groot/Groot.cs +++ b/Groot/Groot.cs @@ -1,4 +1,5 @@ -using System; +using Newtonsoft.Json.Linq; +using System; using System.Collections; using System.Collections.Generic; using System.Collections.Immutable; @@ -78,6 +79,26 @@ private static object ChangeType(PropertyInfo prop, string value) return Convert.ChangeType(value, prop.PropertyType); } + public static string csvToJson(string filePath) + { + var csvlines = File.ReadAllLines(filePath); + var header = csvlines[0].Split(',').Select(s => s.Trim()).ToList(); + JArray array = new JArray(); + for (int i = 1; i < csvlines.Length; i++) + { + JObject jObject = new JObject(); - } + var col = csvlines[i].Split(',').Select(s => s.Trim()).ToList(); + for (int j = 0; j < header.Count; j++) + { + jObject.Add(header[j], col[j]); + } + + array.Add(jObject); + + } + + return array.ToString(); + } + } } \ No newline at end of file diff --git a/Groot/Groot.csproj b/Groot/Groot.csproj index 8fddb85..de77559 100644 --- a/Groot/Groot.csproj +++ b/Groot/Groot.csproj @@ -5,5 +5,6 @@ + \ No newline at end of file