Last active
May 13, 2020 18:03
-
-
Save einarwh/6108ff5198852fb43500e0f28eda7a14 to your computer and use it in GitHub Desktop.
Using a dictionary as target model for deserialization.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var paidCartJsonString = @"{ | |
""_state"": ""paid"", | |
""paidItems"": [ | |
{ | |
""id"": ""1bcd"", | |
""title"": ""gizmo"" | |
}, | |
{ | |
""id"" : ""3cdf"", | |
""title"": ""widget"", | |
""description"": ""A very useful item"" | |
} | |
], | |
""payment"": { | |
""amount"": 123.5, | |
""currency"": ""USD"" | |
}, | |
""timestamp"": ""2020-04-11T10:11:33.514+02:00"" | |
}"; | |
var paidCartBagFromText = JsonConvert.DeserializeObject<Dictionary<string, object>>(paidCartJsonString); | |
var paidItems = (List<object>) paidCartBagFromText["paidItems"]; | |
var firstItem = (Dictionary<string, object>) paidItems[0]; | |
var firstItemTitle = (string) firstItem["title"]; | |
var payment = (Dictionary<string, object>) paidCartBagFromText["payment"]; | |
var currency = (string) payment["currency"]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment