Created
April 26, 2018 11:15
-
-
Save hexagit/4a053fa972e60e4e3b32c62c0e739cd0 to your computer and use it in GitHub Desktop.
TestCode
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <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