API Response :
{
"success": true,
"code": 0,
"msg": "성공하였습니다.",
"list": [
{
"code": "ANT",
"code_name": "소둔구분",
"p_code": "",
"p_code_name": "",
"code_type": 0,
"code_level": 0,
"max_level": 1,
"description": "GROP : 99 DETL : ANT SUBS : 00",
"create_user": "SYSTEM",
"create_time": "2019-04-24T17:58:58.000+0000",
"disable_yn": "Y"
},
{...}
]
}
C# API Call :
// CodeInfo 초기 데이터 로드
public static DataTable selectAllCodeInfo()
{
DataTable dt = new DataTable();
try
{
var httpWebRequest = (HttpWebRequest)WebRequest.Create(API_ADDRESS + "/api/codeInfo");
httpWebRequest.ContentType = "application/json";
httpWebRequest.Method = "GET";
var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
{
JObject applyObj = JObject.Parse(streamReader.ReadToEnd());
var applyObj2 = streamReader.ReadToEnd();
string success = applyObj["success"].ToString();
if (success.Equals("True"))
{
if (applyObj["list"].ToString() != null)
{
??????????
return dt;
}
} else
{
//API 응답 데이터 수신 실패
}
}
} catch(WebException)
{
//API 서버 닫혀있을때, 연결이 안될때
Console.Write("예외");
return null;
}
catch (Exception)
{
//그 외의 Exception
Console.Write("예외");
return null;
}
return dt;
}
I want to efficiently load the above API call return data values into a DataTable.
I've thought of several ways, but haven't found an efficient way yet.
I have tried to use json data as property object. But it's too cumbersome and inefficient.
Of the Json data above, I want to load only the data contained in the list array as columns and rows in the DataTable.
Is there a good alternative?