Skip to content

Instantly share code, notes, and snippets.

@hexagit
Created April 26, 2018 11:15
Show Gist options
  • Save hexagit/4a053fa972e60e4e3b32c62c0e739cd0 to your computer and use it in GitHub Desktop.
Save hexagit/4a053fa972e60e4e3b32c62c0e739cd0 to your computer and use it in GitHub Desktop.
TestCode
/// <summary>
/// JSON読み込みユーティリティ
/// 参考URL : http://takachan.hatenablog.com/entry/2017/01/18/120000
/// </summary>
public static class JsonUtility
{
public static string GetFileString(string filePath)
{
StreamReader file = new StreamReader(filePath, Encoding.UTF8);
return file.ReadToEnd();
}
public static T Deserialize<T>(string filePath)
{
string fileString = GetFileString(filePath);
using (var stream = new MemoryStream(Encoding.UTF8.GetBytes(fileString)))
{
var serializer = new DataContractJsonSerializer(typeof(T));
return (T)serializer.ReadObject(stream);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment