Answer the question
In order to leave comments, you need to log in
How to convert json to multidimensional array?
There is this JSON:
{
"cities": {
"CountryName": [{
"name": "Sentra"
},
{
"name": "Sentra"
},
{
"name": "Sentra"
}
],
"CountryName2": [{
"name": "Sentra"
},
{
"name": "Sentra"
}
]
}
}
string[,] cities = new string[,] { };
? public class CountryName
{
public string name { get; set; }
}
public class CountryName2
{
public string name { get; set; }
}
public class Cities
{
public List<CountryName> CountryName { get; set; }
public List<CountryName2> CountryName2 { get; set; }
}
public class RootObject
{
public Cities cities { get; set; }
}
Answer the question
In order to leave comments, you need to log in
how to convert?? handles ..
that's right, the site gives you ..
two countries in each list of cities ....
you don't have an array inside cities
, maybe you wanted
{
"cities": [{
"CountryName": [{
"name": "Sentra"
},
{
"name": "Sentra"
},
{
"name": "Sentra"
}
],
"CountryName2": [{
"name": "Sentra"
},
{
"name": "Sentra"
}
]
}
]
}
There is a simple, lazy way: select (preferably large) JSON and edit->paste special -> paste JSON as Classes in the studio
Then we look at the classes, slightly straighten data types, mark data contracts and members and have happiness in the form of successful serializations starting from DataContractJsonSerializer to any fancy out-of-the-box library/framework (like Json.NET)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question