I have JSON coming from an API that looks like this:
{
"GetJsonResult": {
"EntityName": "account",
"FailureReason": "",
"Counter": 0,
"MoreRecords": false,
"OptionSetName": "sic_organisationtitlewad",
"Success": true,
"OptionSetsClean": "[{"Mr":100000000},{"Mrs":100000003},{"Miss":100000002},{"Ms":100000004},{"Prof":100000001},{"Sir":907510000}]",
"OptionSets": [
{
"Mr": 100000000
},
{
"Mrs": 100000003
},
{
"Miss": 100000002
},
{
"Ms": 100000004
},
{
"Prof": 100000001
},
{
"Sir": 907510000
}
],
"Entities": null
}
}
I have a class definition like this:
public class GetJsonResult
{
[JsonProperty("EntityName")]
public string EntityName { get; set; }
[JsonProperty("FailureReason")]
public string FailureReason { get; set; }
[JsonProperty("Counter")]
public int Counter { get; set; }
[JsonProperty("MoreRecords")]
public bool MoreRecords { get; set; }
[JsonProperty("OptionSetName")]
public string? OptionSetName { get; set; }
[JsonProperty("Success")]
public bool Success { get; set; }
[JsonProperty("OptionSetsClean")]
public Dictionary<string, int>? OptionSetsClean { get; set; }
[JsonProperty("OptionSets")]
public object OptionSets { get; set; }
}
And use “JsonConvert.DeserializeObject” to process the data.
I want to get the data in “OptionSetsClean” or in “OptionSets” (they contain the same data) to be converted to something like a Dictionary or List. However, I can’t figure a way of doing that.