Last active
July 14, 2018 00:03
-
-
Save muzudho/f9d94123c21829d5f200d49faf4c6846 to your computer and use it in GitHub Desktop.
C# DynamicJsonの使い方 (1)JSON→クラス (2)JSON→連想配列 ref: https://qiita.com/muzudho1/items/3831ddd06aa3542b9b56
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Codeplex.Data; // DynamicJson はこれ。 | |
using CsharpDynamicJsonBestPractice.Model; // 自分で好きに作れだぜ。 | |
using System.Diagnostics; // Trace とかこれ。 | |
using System.IO; // ファイル読み込みはこれ。 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var json = DynamicJson.Parse(File.ReadAllText("./CsDynamicJsonUsage-config.json")); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 連想配列以外の形は取れるはず。 | |
ConfigModel config = json.Deserialize<ConfigModel>(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### ok | |
public string name { get; set; } | |
### ignored | |
public string name; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 連想配列の形になっている dishMap は、Deserialize では取れない。DynamicJson型から直接取る。 | |
foreach (string key in json.dishMap.GetDynamicMemberNames()) | |
{ | |
Trace.WriteLine($"ENTRY {key} is {json.dishMap[key]}."); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment