我如何在.net中使用newtonsoft json.net在json結構下反序列化。{ "users" : { "parentname":"test", "100034" : { "name" : "tom", "state" : "WA", "id" : "cedf-c56f-18a4-4b1" }, "10045" : { "name" : "steve", "state" : "NY", "id" : "ebb2-92bf-3062-7774" }, "12345" : { "name" : "mike", "state" : "MA", "id" : "fb60-b34f-6dc8-aaf7" } }}我嘗試了下面的代碼,但無法正常工作。我收到錯誤“將值“ test”轉換為類型“ ConsoleApplication2.User”時出錯。路徑“ users.parentname”,第5行,位置35?!眂lass Program { static void Main(string[] args) { string json = @" { ""users"": { ""parentname"":""test"", ""10045"": { ""name"": ""steve"", ""state"": ""NY"", ""id"": ""ebb2-92bf-3062-7774"" } } }"; RootObject root = JsonConvert.DeserializeObject<RootObject>(json); } } class RootObject { public string ParentName { get; set; } public Dictionary<string, User> users { get; set; } } class User { public string name { get; set; } public string state { get; set; } public string id { get; set; } public string ParentName { get; set; } }請提出建議。
- 2 回答
- 0 關注
- 443 瀏覽
添加回答
舉報
0/150
提交
取消