简短版本:如何将JSON字符串反序列化为C#列表或DataTable,而无需将已定义的类反序列化为?
更多解释:我的控制器需要一个json字符串,它是一个对象数组,但该对象的属性是未知的。我需要将其反序列化为一个列表并循环其内容以进行保存。示例json字符串:
1。
[
{"id":"10","name":"User","add":false,"edit":true,"authorize":true,"view":true},
{"id":"11","name":"Group","add":true,"edit":false,"authorize":false,"view":true},
{"id":"12","name":"Permission","add":true,"edit":true,"authorize":true,"view":true}
]
2
[
{"id":"10","name":"User"},
{"id":"11","name":"Group"},
{"id":"12","name":"Permission"}
]
答案 0 :(得分:3)
initialized multiple times
答案 1 :(得分:0)
反序列化您的Json并将其直接转换为数据表。
DataTable dt = (DataTable)JsonConvert.DeserializeObject(jsonText, (typeof(DataTable)));