Skip to content

Commit 4ca7863

Browse files
ReadObjectFromJsonFile option
1 parent c997fed commit 4ca7863

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

ReadJsonFromFile.cs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,43 @@ public CorrectionData(string _source,string _destination)
3434
}
3535
}
3636

37+
38+
public T ReadObjectFromJsonFile(String Filepath, List<CorrectionData> dataCorrection = null, Boolean debug = false)
39+
{
40+
string json = string.Empty;
41+
42+
T value;
43+
44+
45+
46+
47+
using (StreamReader read = new StreamReader(Filepath))
48+
{
49+
json = read.ReadToEnd();
50+
if (dataCorrection != null)
51+
{
52+
53+
foreach (CorrectionData item in dataCorrection)
54+
{
55+
json = Regex.Replace(json, item.source, item.destination);
56+
}
57+
58+
}
59+
60+
if (debug)
61+
{
62+
File.WriteAllText(Filepath + ".debug", json);
63+
}
64+
65+
66+
value = (T)JsonConvert.DeserializeObject(json, typeof(T));
67+
68+
69+
70+
}
71+
return value;
72+
}
73+
3774
public class ReadJsonFromFile<T>
3875
{
3976
public List<T> ReadListObjectJsonFile(String Filepath, List<CorrectionData> dataCorrection = null, Boolean debug = false)

0 commit comments

Comments
 (0)