По какой-то причине непустой массив строк в Json после десериализации становится свойством класса с нулевым значением, тогда как он должен стать непустым List<string>
.
Вот JSON:
{"data":{"places":{"А":["037","038","039","040","041","042","043","044","045","046","049","050","051","052"]},"schemeId":"П01","scheme":"{\"scheme_type\":\"П01\",\"model\":{\"floor\":{\"1\":{\"width\":20,\"height\":4}}},\"places\":{\"floor\":{\"1\":[{\"y\":1,\"x\":2,\"w\":1,\"h\":1,\"num\":\"2\",\"pos\":\"up\",\"type\":\"place\"},{\"y\":1,\"x\":3,\"w\":1,\"h\":1,\"num\":\"4\",\"pos\":\"up\",\"type\":\"place\"},{\"y\":1,\"x\":4,\"w\":1,\"h\":1,\"num\":\"6\",\"pos\":\"up\",\"type\":\"place\"},{\"y\":1,\"x\":5,\"w\":1,\"h\":1,\"num\":\"8\",\"pos\":\"up\",\"type\":\"place\"},{\"y\":1,\"x\":6,\"w\":1,\"h\":1,\"num\":\"10\",\"pos\":\"up\",\"type\":\"place\"},{\"y\":1,\"x\":7,\"w\":1,\"h\":1,\"num\":\"12\",\"pos\":\"up\",\"type\":\"place\"},{\"y\":1,\"x\":8,\"w\":1,\"h\":1,\"num\":\"14\",\"pos\":\"up\",\"type\":\"place\"},{\"y\":1,\"x\":9,\"w\":1,\"h\":1,\"num\":\"16\",\"pos\":\"up\",\"type\":\"place\"},{\"y\":1,\"x\":10,\"w\":1,\"h\":1,\"num\":\"18\",\"pos\":\"up\",\"type\":\"place\"},{\"y\":1,\"x\":11,\"w\":1,\"h\":1,\"num\":\"20\",\"pos\":\"up\",\"type\":\"place\"},{\"y\":1,\"x\":12,\"w\":1,\"h\":1,\"num\":\"22\",\"pos\":\"up\",\"type\":\"place\"},{\"y\":1,\"x\":13,\"w\":1,\"h\":1,\"num\":\"24\",\"pos\":\"up\",\"type\":\"place\"},{\"y\":1,\"x\":14,\"w\":1,\"h\":1,\"num\":\"26\",\"pos\":\"up\",\"type\":\"place\"},{\"y\":1,\"x\":15,\"w\":1,\"h\":1,\"num\":\"28\",\"pos\":\"up\",\"type\":\"place\"},{\"y\":1,\"x\":16,\"w\":1,\"h\":1,\"num\":\"30\",\"pos\":\"up\",\"type\":\"place\"},{\"y\":1,\"x\":17,\"w\":1,\"h\":1,\"num\":\"32\",\"pos\":\"up\",\"type\":\"place\"},{\"y\":1,\"x\":18,\"w\":1,\"h\":1,\"num\":\"34\",\"pos\":\"up\",\"type\":\"place\"},{\"y\":1,\"x\":19,\"w\":1,\"h\":1,\"num\":\"36\",\"pos\":\"up\",\"type\":\"place\"},{\"y\":2,\"x\":2,\"w\":1,\"h\":1,\"num\":\"1\",\"pos\":\"down\",\"type\":\"place\"},{\"y\":2,\"x\":3,\"w\":1,\"h\":1,\"num\":\"3\",\"pos\":\"down\",\"type\":\"place\"},{\"y\":2,\"x\":4,\"w\":1,\"h\":1,\"num\":\"5\",\"pos\":\"down\",\"type\":\"place\"},{\"y\":2,\"x\":5,\"w\":1,\"h\":1,\"num\":\"7\",\"pos\":\"down\",\"type\":\"place\"},{\"y\":2,\"x\":6,\"w\":1,\"h\":1,\"num\":\"9\",\"pos\":\"down\",\"type\":\"place\"},{\"y\":2,\"x\":7,\"w\":1,\"h\":1,\"num\":\"11\",\"pos\":\"down\",\"type\":\"place\"},{\"y\":2,\"x\":8,\"w\":1,\"h\":1,\"num\":\"13\",\"pos\":\"down\",\"type\":\"place\"},{\"y\":2,\"x\":9,\"w\":1,\"h\":1,\"num\":\"15\",\"pos\":\"down\",\"type\":\"place\"},{\"y\":2,\"x\":10,\"w\":1,\"h\":1,\"num\":\"17\",\"pos\":\"down\",\"type\":\"place\"},{\"y\":2,\"x\":11,\"w\":1,\"h\":1,\"num\":\"19\",\"pos\":\"down\",\"type\":\"place\"},{\"y\":2,\"x\":12,\"w\":1,\"h\":1,\"num\":\"21\",\"pos\":\"down\",\"type\":\"place\"},{\"y\":2,\"x\":13,\"w\":1,\"h\":1,\"num\":\"23\",\"pos\":\"down\",\"type\":\"place\"},{\"y\":2,\"x\":14,\"w\":1,\"h\":1,\"num\":\"25\",\"pos\":\"down\",\"type\":\"place\"},{\"y\":2,\"x\":15,\"w\":1,\"h\":1,\"num\":\"27\",\"pos\":\"down\",\"type\":\"place\"},{\"y\":2,\"x\":16,\"w\":1,\"h\":1,\"num\":\"29\",\"pos\":\"down\",\"type\":\"place\"},{\"y\":2,\"x\":17,\"w\":1,\"h\":1,\"num\":\"31\",\"pos\":\"down\",\"type\":\"place\"},{\"y\":2,\"x\":18,\"w\":1,\"h\":1,\"num\":\"33\",\"pos\":\"down\",\"type\":\"place\"},{\"y\":2,\"x\":19,\"w\":1,\"h\":1,\"num\":\"35\",\"pos\":\"down\",\"type\":\"place\"},{\"y\":4,\"x\":2,\"w\":1,\"h\":1,\"num\":\"54\",\"pos\":\"up\",\"type\":\"place\"},{\"y\":4,\"x\":3,\"w\":1,\"h\":1,\"num\":\"53\",\"pos\":\"down\",\"type\":\"place\"},{\"y\":4,\"x\":4,\"w\":1,\"h\":1,\"num\":\"52\",\"pos\":\"up\",\"type\":\"place\"},{\"y\":4,\"x\":5,\"w\":1,\"h\":1,\"num\":\"51\",\"pos\":\"down\",\"type\":\"place\"},{\"y\":4,\"x\":6,\"w\":1,\"h\":1,\"num\":\"50\",\"pos\":\"up\",\"type\":\"place\"},{\"y\":4,\"x\":7,\"w\":1,\"h\":1,\"num\":\"49\",\"pos\":\"down\",\"type\":\"place\"},{\"y\":4,\"x\":8,\"w\":1,\"h\":1,\"num\":\"48\",\"pos\":\"up\",\"type\":\"place\"},{\"y\":4,\"x\":9,\"w\":1,\"h\":1,\"num\":\"47\",\"pos\":\"down\",\"type\":\"place\"},{\"y\":4,\"x\":10,\"w\":1,\"h\":1,\"num\":\"46\",\"pos\":\"up\",\"type\":\"place\"},{\"y\":4,\"x\":11,\"w\":1,\"h\":1,\"num\":\"45\",\"pos\":\"down\",\"type\":\"place\"},{\"y\":4,\"x\":12,\"w\":1,\"h\":1,\"num\":\"44\",\"pos\":\"up\",\"type\":\"place\"},{\"y\":4,\"x\":13,\"w\":1,\"h\":1,\"num\":\"43\",\"pos\":\"down\",\"type\":\"place\"},{\"y\":4,\"x\":14,\"w\":1,\"h\":1,\"num\":\"42\",\"pos\":\"up\",\"type\":\"place\"},{\"y\":4,\"x\":15,\"w\":1,\"h\":1,\"num\":\"41\",\"pos\":\"down\",\"type\":\"place\"},{\"y\":4,\"x\":16,\"w\":1,\"h\":1,\"num\":\"40\",\"pos\":\"up\",\"type\":\"place\"},{\"y\":4,\"x\":17,\"w\":1,\"h\":1,\"num\":\"39\",\"pos\":\"down\",\"type\":\"place\"},{\"y\":4,\"x\":18,\"w\":1,\"h\":1,\"num\":\"38\",\"pos\":\"up\",\"type\":\"place\"},{\"y\":4,\"x\":19,\"w\":1,\"h\":1,\"num\":\"37\",\"pos\":\"down\",\"type\":\"place\"},{\"y\":1,\"x\":1,\"h\":1,\"type\":\"wall\"},{\"y\":1,\"x\":2,\"h\":2,\"type\":\"wall\"},{\"y\":1,\"x\":4,\"h\":2,\"type\":\"wall\"},{\"y\":1,\"x\":6,\"h\":2,\"type\":\"wall\"},{\"y\":1,\"x\":8,\"h\":2,\"type\":\"wall\"},{\"y\":1,\"x\":10,\"h\":2,\"type\":\"wall\"},{\"y\":1,\"x\":12,\"h\":2,\"type\":\"wall\"},{\"y\":1,\"x\":14,\"h\":2,\"type\":\"wall\"},{\"y\":1,\"x\":16,\"h\":2,\"type\":\"wall\"},{\"y\":1,\"x\":18,\"h\":2,\"type\":\"wall\"},{\"y\":1,\"x\":20,\"h\":2,\"type\":\"wall\"},{\"y\":1,\"x\":21,\"h\":2,\"type\":\"wall\"},{\"y\":4,\"x\":2,\"h\":1,\"type\":\"wall\"},{\"y\":4,\"x\":1,\"h\":1,\"type\":\"wall\"},{\"y\":4,\"x\":4,\"h\":1,\"type\":\"wall\"},{\"y\":4,\"x\":6,\"h\":1,\"type\":\"wall\"},{\"y\":4,\"x\":8,\"h\":1,\"type\":\"wall\"},{\"y\":4,\"x\":10,\"h\":1,\"type\":\"wall\"},{\"y\":4,\"x\":12,\"h\":1,\"type\":\"wall\"},{\"y\":4,\"x\":14,\"h\":1,\"type\":\"wall\"},{\"y\":4,\"x\":16,\"h\":1,\"type\":\"wall\"},{\"y\":4,\"x\":18,\"h\":1,\"type\":\"wall\"},{\"y\":4,\"x\":20,\"h\":1,\"type\":\"wall\"},{\"y\":4,\"x\":21,\"h\":1,\"type\":\"wall\"},{\"y\":1,\"x\":1,\"w\":1,\"h\":1,\"type\":\"toilet\"},{\"y\":1,\"x\":20,\"w\":1,\"h\":1,\"type\":\"toilet\"}]}}}"}}
Тот же самый json, но проанализированный (для лучшей читаемости):
{
"data": {
"places": {
"А": [
"037",
"038",
"039",
"040",
"041",
"042",
"043",
"044",
"045",
"046",
"049",
"050",
"051",
"052"
]
},
"schemeId": "П01",
"scheme": "{\"scheme_type\":\"П01\",\"model\":{\"floor\":{\"1\":{\"width\":20,\"height\":4}}},\"places\":{\"floor\":{\"1\":[{\"y\":1,\"x\":2,\"w\":1,\"h\":1,\"num\":\"2\",\"pos\":\"up\",\"type\":\"place\"},{\"y\":1,\"x\":3,\"w\":1,\"h\":1,\"num\":\"4\",\"pos\":\"up\",\"type\":\"place\"},{\"y\":1,\"x\":4,\"w\":1,\"h\":1,\"num\":\"6\",\"pos\":\"up\",\"type\":\"place\"},{\"y\":1,\"x\":5,\"w\":1,\"h\":1,\"num\":\"8\",\"pos\":\"up\",\"type\":\"place\"},{\"y\":1,\"x\":6,\"w\":1,\"h\":1,\"num\":\"10\",\"pos\":\"up\",\"type\":\"place\"},{\"y\":1,\"x\":7,\"w\":1,\"h\":1,\"num\":\"12\",\"pos\":\"up\",\"type\":\"place\"},{\"y\":1,\"x\":8,\"w\":1,\"h\":1,\"num\":\"14\",\"pos\":\"up\",\"type\":\"place\"},{\"y\":1,\"x\":9,\"w\":1,\"h\":1,\"num\":\"16\",\"pos\":\"up\",\"type\":\"place\"},{\"y\":1,\"x\":10,\"w\":1,\"h\":1,\"num\":\"18\",\"pos\":\"up\",\"type\":\"place\"},{\"y\":1,\"x\":11,\"w\":1,\"h\":1,\"num\":\"20\",\"pos\":\"up\",\"type\":\"place\"},{\"y\":1,\"x\":12,\"w\":1,\"h\":1,\"num\":\"22\",\"pos\":\"up\",\"type\":\"place\"},{\"y\":1,\"x\":13,\"w\":1,\"h\":1,\"num\":\"24\",\"pos\":\"up\",\"type\":\"place\"},{\"y\":1,\"x\":14,\"w\":1,\"h\":1,\"num\":\"26\",\"pos\":\"up\",\"type\":\"place\"},{\"y\":1,\"x\":15,\"w\":1,\"h\":1,\"num\":\"28\",\"pos\":\"up\",\"type\":\"place\"},{\"y\":1,\"x\":16,\"w\":1,\"h\":1,\"num\":\"30\",\"pos\":\"up\",\"type\":\"place\"},{\"y\":1,\"x\":17,\"w\":1,\"h\":1,\"num\":\"32\",\"pos\":\"up\",\"type\":\"place\"},{\"y\":1,\"x\":18,\"w\":1,\"h\":1,\"num\":\"34\",\"pos\":\"up\",\"type\":\"place\"},{\"y\":1,\"x\":19,\"w\":1,\"h\":1,\"num\":\"36\",\"pos\":\"up\",\"type\":\"place\"},{\"y\":2,\"x\":2,\"w\":1,\"h\":1,\"num\":\"1\",\"pos\":\"down\",\"type\":\"place\"},{\"y\":2,\"x\":3,\"w\":1,\"h\":1,\"num\":\"3\",\"pos\":\"down\",\"type\":\"place\"},{\"y\":2,\"x\":4,\"w\":1,\"h\":1,\"num\":\"5\",\"pos\":\"down\",\"type\":\"place\"},{\"y\":2,\"x\":5,\"w\":1,\"h\":1,\"num\":\"7\",\"pos\":\"down\",\"type\":\"place\"},{\"y\":2,\"x\":6,\"w\":1,\"h\":1,\"num\":\"9\",\"pos\":\"down\",\"type\":\"place\"},{\"y\":2,\"x\":7,\"w\":1,\"h\":1,\"num\":\"11\",\"pos\":\"down\",\"type\":\"place\"},{\"y\":2,\"x\":8,\"w\":1,\"h\":1,\"num\":\"13\",\"pos\":\"down\",\"type\":\"place\"},{\"y\":2,\"x\":9,\"w\":1,\"h\":1,\"num\":\"15\",\"pos\":\"down\",\"type\":\"place\"},{\"y\":2,\"x\":10,\"w\":1,\"h\":1,\"num\":\"17\",\"pos\":\"down\",\"type\":\"place\"},{\"y\":2,\"x\":11,\"w\":1,\"h\":1,\"num\":\"19\",\"pos\":\"down\",\"type\":\"place\"},{\"y\":2,\"x\":12,\"w\":1,\"h\":1,\"num\":\"21\",\"pos\":\"down\",\"type\":\"place\"},{\"y\":2,\"x\":13,\"w\":1,\"h\":1,\"num\":\"23\",\"pos\":\"down\",\"type\":\"place\"},{\"y\":2,\"x\":14,\"w\":1,\"h\":1,\"num\":\"25\",\"pos\":\"down\",\"type\":\"place\"},{\"y\":2,\"x\":15,\"w\":1,\"h\":1,\"num\":\"27\",\"pos\":\"down\",\"type\":\"place\"},{\"y\":2,\"x\":16,\"w\":1,\"h\":1,\"num\":\"29\",\"pos\":\"down\",\"type\":\"place\"},{\"y\":2,\"x\":17,\"w\":1,\"h\":1,\"num\":\"31\",\"pos\":\"down\",\"type\":\"place\"},{\"y\":2,\"x\":18,\"w\":1,\"h\":1,\"num\":\"33\",\"pos\":\"down\",\"type\":\"place\"},{\"y\":2,\"x\":19,\"w\":1,\"h\":1,\"num\":\"35\",\"pos\":\"down\",\"type\":\"place\"},{\"y\":4,\"x\":2,\"w\":1,\"h\":1,\"num\":\"54\",\"pos\":\"up\",\"type\":\"place\"},{\"y\":4,\"x\":3,\"w\":1,\"h\":1,\"num\":\"53\",\"pos\":\"down\",\"type\":\"place\"},{\"y\":4,\"x\":4,\"w\":1,\"h\":1,\"num\":\"52\",\"pos\":\"up\",\"type\":\"place\"},{\"y\":4,\"x\":5,\"w\":1,\"h\":1,\"num\":\"51\",\"pos\":\"down\",\"type\":\"place\"},{\"y\":4,\"x\":6,\"w\":1,\"h\":1,\"num\":\"50\",\"pos\":\"up\",\"type\":\"place\"},{\"y\":4,\"x\":7,\"w\":1,\"h\":1,\"num\":\"49\",\"pos\":\"down\",\"type\":\"place\"},{\"y\":4,\"x\":8,\"w\":1,\"h\":1,\"num\":\"48\",\"pos\":\"up\",\"type\":\"place\"},{\"y\":4,\"x\":9,\"w\":1,\"h\":1,\"num\":\"47\",\"pos\":\"down\",\"type\":\"place\"},{\"y\":4,\"x\":10,\"w\":1,\"h\":1,\"num\":\"46\",\"pos\":\"up\",\"type\":\"place\"},{\"y\":4,\"x\":11,\"w\":1,\"h\":1,\"num\":\"45\",\"pos\":\"down\",\"type\":\"place\"},{\"y\":4,\"x\":12,\"w\":1,\"h\":1,\"num\":\"44\",\"pos\":\"up\",\"type\":\"place\"},{\"y\":4,\"x\":13,\"w\":1,\"h\":1,\"num\":\"43\",\"pos\":\"down\",\"type\":\"place\"},{\"y\":4,\"x\":14,\"w\":1,\"h\":1,\"num\":\"42\",\"pos\":\"up\",\"type\":\"place\"},{\"y\":4,\"x\":15,\"w\":1,\"h\":1,\"num\":\"41\",\"pos\":\"down\",\"type\":\"place\"},{\"y\":4,\"x\":16,\"w\":1,\"h\":1,\"num\":\"40\",\"pos\":\"up\",\"type\":\"place\"},{\"y\":4,\"x\":17,\"w\":1,\"h\":1,\"num\":\"39\",\"pos\":\"down\",\"type\":\"place\"},{\"y\":4,\"x\":18,\"w\":1,\"h\":1,\"num\":\"38\",\"pos\":\"up\",\"type\":\"place\"},{\"y\":4,\"x\":19,\"w\":1,\"h\":1,\"num\":\"37\",\"pos\":\"down\",\"type\":\"place\"},{\"y\":1,\"x\":1,\"h\":1,\"type\":\"wall\"},{\"y\":1,\"x\":2,\"h\":2,\"type\":\"wall\"},{\"y\":1,\"x\":4,\"h\":2,\"type\":\"wall\"},{\"y\":1,\"x\":6,\"h\":2,\"type\":\"wall\"},{\"y\":1,\"x\":8,\"h\":2,\"type\":\"wall\"},{\"y\":1,\"x\":10,\"h\":2,\"type\":\"wall\"},{\"y\":1,\"x\":12,\"h\":2,\"type\":\"wall\"},{\"y\":1,\"x\":14,\"h\":2,\"type\":\"wall\"},{\"y\":1,\"x\":16,\"h\":2,\"type\":\"wall\"},{\"y\":1,\"x\":18,\"h\":2,\"type\":\"wall\"},{\"y\":1,\"x\":20,\"h\":2,\"type\":\"wall\"},{\"y\":1,\"x\":21,\"h\":2,\"type\":\"wall\"},{\"y\":4,\"x\":2,\"h\":1,\"type\":\"wall\"},{\"y\":4,\"x\":1,\"h\":1,\"type\":\"wall\"},{\"y\":4,\"x\":4,\"h\":1,\"type\":\"wall\"},{\"y\":4,\"x\":6,\"h\":1,\"type\":\"wall\"},{\"y\":4,\"x\":8,\"h\":1,\"type\":\"wall\"},{\"y\":4,\"x\":10,\"h\":1,\"type\":\"wall\"},{\"y\":4,\"x\":12,\"h\":1,\"type\":\"wall\"},{\"y\":4,\"x\":14,\"h\":1,\"type\":\"wall\"},{\"y\":4,\"x\":16,\"h\":1,\"type\":\"wall\"},{\"y\":4,\"x\":18,\"h\":1,\"type\":\"wall\"},{\"y\":4,\"x\":20,\"h\":1,\"type\":\"wall\"},{\"y\":4,\"x\":21,\"h\":1,\"type\":\"wall\"},{\"y\":1,\"x\":1,\"w\":1,\"h\":1,\"type\":\"toilet\"},{\"y\":1,\"x\":20,\"w\":1,\"h\":1,\"type\":\"toilet\"}]}}}"
}
}
Я использовал http://json2csharp.com/, чтобы добавить правильные классы, которые соответствуют этому конкретному json. Я переименовал некоторые имена типов, но структура такая же, какой была раньше.
Вот код классов:
public class Places
{
public List<string> available_places { get; set; }
}
public class TicketsData
{
public Places places { get; set; }
public string schemeId { get; set; }
public string scheme { get; set; }
}
public class TicketsRootObject
{
public TicketsData data { get; set; }
}
И вот тут я наткнулся на проблему:
TicketsRootObject tickets_root_obj = JsonConvert.DeserializeObject<TicketsRootObject>(
/*json string here*/);
List<string> available_tickets_str = tickets_root_obj.data.places.available_places;
available_places
поле имеет значение null, в то время как оно должно стать списком строк "037","038","039","040","041","042","043","044","045","046","049","050","051","052"
Я также пытался использовать имена классов и свойств "как есть" (без переименования) из http://json2csharp.com/. Не помогло.
И похоже, что структура классов и свойств соответствует json, потому что в противном случае это даст мне исключение при разборе, или весь RootObject будет нулевым.
На всякий случай я попытался также изменить тип available_places с List<string>
на List<int>
.
Вопросы о преобразовании Json в C # задавались, вероятно, миллиард раз, но я не нашел подходящего для этого случая. Что мне здесь не хватает?