2020年8月5日 星期三

JsonToDataTable

參考:
  1. https://rextester.com/LTRMYJ47380
  2. https://gist.github.com/KyleShen/88ef81e7e279b376e2f26dc9469d7d2e
方法:透過Newtonsoft.Json套件傳換

    string jsonString= "[{\"id\":3,\"name\":\"peter\"}]";
    DataTable dt = (DataTable)JsonConvert.DeserializeObject(jsonString, (typeof(DataTable)));

注意點:
    以此案例所傳的jsonstring一定要是以"[" 開頭"]" 的字串。(array)