我有一个JSON字符串,它有动态字段,如下所示
"errors": {
"StartTime, StopTime": [
"lorem ipsum","doh rey mee far so lar ti doo","this is an error"
],
"SetupMinutes": [
"Insufficient time until StartTime to allow for SetupMinutes",
"Quick brown fox jumps over the lazy dog"
],
"Another field with an error" : [
"This field is bad", "this field is bad too", "all fields are bad"
],
"propX":["this is another field","this is another item"],
"propY":["this is another field","this is another item"]
"的所有子字段;错误";是动态的。
如何将其反序列化为动态JSON对象?
IMHO,字典是最适合动态字段的
Dictionary<string,string[]> errors = JObject.Parse(json)["errors"].ToObject<Dictionary<string,string[]>>();
如何使用
string startStopTime = string.Join(",",errors["StartTime, StopTime"]);
//result
"lorem ipsum,doh rey mee far so lar ti doo,this is an error"