Skip to content

Instantly share code, notes, and snippets.

@muzudho
Last active July 14, 2018 00:03
Show Gist options
  • Save muzudho/f9d94123c21829d5f200d49faf4c6846 to your computer and use it in GitHub Desktop.
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
using Codeplex.Data; // DynamicJson はこれ。
using CsharpDynamicJsonBestPractice.Model; // 自分で好きに作れだぜ。
using System.Diagnostics; // Trace とかこれ。
using System.IO; // ファイル読み込みはこれ。
var json = DynamicJson.Parse(File.ReadAllText("./CsDynamicJsonUsage-config.json"));
// 連想配列以外の形は取れるはず。
ConfigModel config = json.Deserialize<ConfigModel>();
### ok
public string name { get; set; }
### ignored
public string name;
// 連想配列の形になっている 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