You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

40 lines
1.6 KiB

1 year ago
  1. using Newtonsoft.Json;
  2. using System.IO;
  3. namespace Common.JsonFileParsing
  4. {
  5. public class JsonFileParsing
  6. {
  7. //로컬 사용
  8. //private readonly static string rootpath = AppDomain.CurrentDomain.BaseDirectory + "..//Common/JsonFileParsing/JsonTable/";
  9. //UAT 사용
  10. //private readonly static string rootpath = "D:\\HOSTING\\UAT\\UAT-JSONRX-API\\App_Data\\JsonFile\\";
  11. //Storage 사용 ( 아직 주소 제대로미지정 )
  12. //
  13. //private readonly static string rootpath = "D:\\HOSTING\\STAGE\\STAGE-JSONRX-API\\App_Data\\JsonFile\\";
  14. private readonly static string rootpath = "D:\\API-Live\\GME-MOBILE-API\\App_Data\\JsonFile\\";
  15. /// <summary>
  16. /// json 파싱 함수 T 타입이 Generic Type 경우 Json 파일 명을 path 에 넣어준다. path string 입력 T 타입이 Class 경우
  17. /// 클래스 명과 파일 이름을 일치 시켜준다. path string 입력안해도됌
  18. /// </summary>
  19. /// <typeparam name="T"></typeparam>
  20. /// <param name="path"></param>
  21. /// <returns></returns>
  22. public static T Deserialize<T>(string path = "")
  23. {
  24. var typeName = typeof(T);
  25. if (typeName.IsGenericType == false)
  26. {
  27. path = typeName.Name;
  28. }
  29. using (StreamReader r = new StreamReader(rootpath + path + ".json"))
  30. {
  31. var json = r.ReadToEnd();
  32. var parsingResult = JsonConvert.DeserializeObject<T>(json);
  33. return parsingResult;
  34. }
  35. }
  36. }
  37. }