{
"id": "zd_tags",
"value": [
"bp_ticket;pazure_server"
]
},
{
"id": "itd_priority_1",
"value": 900
},
{
"id": "impacted_services",
"value": [
"Serverdown0208_2"
]
},
I am unable to read and deserialize the JSON into my objects which throws the below error.
"$.incidentTags[6].value": [
"The JSON value could not be converted to System.String[]. Path: $.incidentTags[6].value | LineNumber: 0 | BytePositionInLine: 1856."
]
Below is my current structure to deserialize it.
public class incidentTag
{
public string id { get; set; }
public string[] value {get;set;}
}
Here is the problem, Some tag has no array " "id": "itd_priority_1" but many have an array of value.
What is the best way to handle this scenario?
4
Answers
Old Post for fixing this issue
The Above link helped me to resolve the problem and one more thing is, need to add the reference for "Microsoft.AspNetCore.Mvc.NewtonsoftJson;".I guess, .Net core 6 is using the System.text.Json which has an issue or does not support this operation.
Cant make a comment so having to make an answer.
Previously I have used a dynamic for if the data is unstructured or I don’t know the data structure. An example of how I have used a dynamic is below
I presume similar could be applied to your use case
Either you can create a custom json converter to handle the parsing the way you want it, there are many examples you can look for it.
Or as an altenative you can use
JObject
, something like this, parse the json and visit theJPproperty
inJObject
and check whether that is array or object or any other primitive type.I usually create a json constructor in this case