In one of my project i want to parse a JSON array with different key name. For Example
{ "details": [
{ "state": "myState1",
"place": [
{ "name": "placeName" } ] },
{ "state": "myState2",
"place": [
{ "name1": "placeName" } ] },
{ "state": "myState3",
"place": [
{ "name2": "placeName" } ] } }
So in this JSON please look at the place array. each time key like name1,name2,name3…,
.And also it is not necessary to get the same JSON at all the time. In some time only state1 or state1 and state3 and in some time state1 to state 50.
So how can i identify and parse exact data from this array
First of all your JSON is not well-formatted. You miss a closing square bracket
]before the last closing curly bracket}.Then, you can’t parse variable-name properties to a static class, but you can turn them into a dictionary. Here’s an example of mapping classes that work with variable
places:If also the
placeproperty will change name, I think the simplest way to parse it is to use the following, very loosely typed, class:where the object in the dictionary will be a string or a dictionary of properties according to the values in the JSON.