Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add csvToJson #18

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions Groot/Groot.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using Newtonsoft.Json.Linq;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Immutable;
Expand Down Expand Up @@ -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();
}
}
}
1 change: 1 addition & 0 deletions Groot/Groot.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="AltCover" Version="4.0.644" />
<PackageReference Include="Newtonsoft.Json" Version="11.0.2" />
</ItemGroup>
</Project>