我正面临将下面的json转换为类注释列表
的困难[{"12":{"id":"12","cdate":"2018-05-16 00:32:53","note":"Some notes will go here...","first_name":"Mark","last_name":"1"}},
{"13":{"id":"13","cdate":"2018-05-16 00:32:53","note":"Some notes will go here...","first_name":"Mark","last_name":"1"}},
{"14":{"id":"14","cdate":"2018-05-16 00:32:53","note":"Some notes will go here...","first_name":"Mark","last_name":"1"}}]
我正在使用下面的课程
public class Notes{
public int id {get; set;}
public DateTime cdate {get; set;}
public string note {get; set;}
public string first_name {get; set;}
public string last_name {get; set;}
}
基本上我试图将上面指定的json中的所有值转换为类“Notes”的列表。我遇到了麻烦,因为它有不同的钥匙。
我尝试使用以下代码
var rowJson = JsonConvert.SerializeObject(acDealInfo.deal_notes);
var oDealNotes = JObject.Parse(rowJson);
var result = oDealNotes
.OfType<JProperty>()
.Select(p => new KeyValuePair<string, object>(p.Path,
p.Value.Type == JTokenType.Array || p.Value.Type == JTokenType.Object
? null : p.Value));