將 JSON 轉換為 C# 物件:逐步指南
可以透過簡單的方式將 JSON 資料轉換為對應的 C# 物件過程。以下是所涉及步驟的細分:
1.利用 Visual Studio 的內建轉換功能:
2.安裝 NuGet 依賴項:
3.將JSON 反序列化為C# 物件:
Rootobject r = Newtonsoft.Json.JsonConvert.DeserializeObject<Rootobject>(jsonString);
範例JSON 資料:
{ "err_code": "0", "org": "CGK", "des": "SIN", "flight_date": "20120719", "schedule": [ ["W2-888","20120719","20120719","1200","1600","03h00m","737-200","0",[["K","9"],["F","9"],["L","9"],["M","9"],["N","9"],["P","9"],["C","9"],["O","9"]]], ["W2-999","20120719","20120719","1800","2000","01h00m","MD-83","0",[["K","9"],["L","9"],["M","9"],["N","9"]]] ] }
預期結果:
以上是如何有效地將JSON資料轉換為C#物件?的詳細內容。更多資訊請關注PHP中文網其他相關文章!