I have two auto generated JSON data as shown below. I want to get all the data in Colors Tag. I Created a JArray of "Colors" and started looping on all data available, but when there is only one color available my code starts giving exceptions as "Colors" is not a JArray instead a JProperty. See sample code below.
What is the ideal way of handling this situation?
{
"UID":1234,
"Colors":["red", "blue", "green"]
}
{
"UID":1234,
"Colors":"green"
}
JObject jsonObject = (JObject)JsonConvert.DeserializeObject(jsonText, settings);
foreach (JObject reg in jsonObject["Colors"]) {
// Write to console.
}