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.
 
 
 

41 lines
1.6 KiB

using Newtonsoft.Json;
using System.IO;
namespace Common.JsonFileParsing
{
public class JsonFileParsing
{
//로컬 사용
//private readonly static string rootpath = AppDomain.CurrentDomain.BaseDirectory + "..//Common/JsonFileParsing/JsonTable/";
//UAT 사용
//private readonly static string rootpath = "D:\\HOSTING\\UAT\\UAT-JSONRX-API\\App_Data\\JsonFile\\";
//Storage 사용 ( 아직 주소 제대로미지정 )
//
//private readonly static string rootpath = "D:\\HOSTING\\STAGE\\STAGE-JSONRX-API\\App_Data\\JsonFile\\";
private readonly static string rootpath = "D:\\API-Live\\GME-MOBILE-API\\App_Data\\JsonFile\\";
/// <summary>
/// json 파싱 함수 T 타입이 Generic Type 경우 Json 파일 명을 path 에 넣어준다. path string 입력 T 타입이 Class 경우
/// 클래스 명과 파일 이름을 일치 시켜준다. path string 입력안해도됌
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="path"></param>
/// <returns></returns>
public static T Deserialize<T>(string path = "")
{
var typeName = typeof(T);
if (typeName.IsGenericType == false)
{
path = typeName.Name;
}
using (StreamReader r = new StreamReader(rootpath + path + ".json"))
{
var json = r.ReadToEnd();
var parsingResult = JsonConvert.DeserializeObject<T>(json);
return parsingResult;
}
}
}
}