Я пытаюсь десериализовать следующие данные json в классы в течение 2 дней, используя справку из похожих вопросов на этом и других сайтах, и, возможно, это может привести к смерти мозга.преобразовать комплекс json в C# class
У меня есть этот JSon данные (Извиняюсь за длину), и я пытаюсь, как начать, чтобы получить «значение» число в массиве «ценности»: -
{
"metadata": {
"columnGrouping": [
"area",
"metricType",
"period",
"valueType"
],
"rowGrouping": []
},
"columns": [
{
"area": {
"identifier": "E31000040",
"label": "Gtr Manchester Fire",
"altLabel": "Gtr Manchester Fire",
"isSummary": false
},
"metricType": {
"identifier": "948",
"label": "Accidental dwelling fires",
"altLabel": "Accidental dwelling fires",
"isSummary": false
},
"period": {
"identifier": "fq_Q1_2013_14",
"label": "2013/14 Q1",
"altLabel": "2013/14 Q1",
"isSummary": false
},
"valueType": {
"identifier": "raw",
"label": "Raw value",
"isSummary": false
}
},
{
"area": {
"identifier": "E31000040",
"label": "Gtr Manchester Fire",
"altLabel": "Gtr Manchester Fire",
"isSummary": false
},
"metricType": {
"identifier": "948",
"label": "Accidental dwelling fires",
"altLabel": "Accidental dwelling fires",
"isSummary": false
},
"period": {
"identifier": "fq_Q2_2013_14",
"label": "2013/14 Q2",
"altLabel": "2013/14 Q2",
"isSummary": false
},
"valueType": {
"identifier": "raw",
"label": "Raw value",
"isSummary": false
}
},
{
"area": {
"identifier": "E31000040",
"label": "Gtr Manchester Fire",
"altLabel": "Gtr Manchester Fire",
"isSummary": false
},
"metricType": {
"identifier": "948",
"label": "Accidental dwelling fires",
"altLabel": "Accidental dwelling fires",
"isSummary": false
},
"period": {
"identifier": "fq_Q3_2013_14",
"label": "2013/14 Q3",
"altLabel": "2013/14 Q3",
"isSummary": false
},
"valueType": {
"identifier": "raw",
"label": "Raw value",
"isSummary": false
}
},
{
"area": {
"identifier": "E31000040",
"label": "Gtr Manchester Fire",
"altLabel": "Gtr Manchester Fire",
"isSummary": false
},
"metricType": {
"identifier": "948",
"label": "Accidental dwelling fires",
"altLabel": "Accidental dwelling fires",
"isSummary": false
},
"period": {
"identifier": "fq_Q4_2013_14",
"label": "2013/14 Q4",
"altLabel": "2013/14 Q4",
"isSummary": false
},
"valueType": {
"identifier": "raw",
"label": "Raw value",
"isSummary": false
}
}
],
"rows": [
{
"values": [
{
"source": 515.0,
"value": 515.0,
"formatted": "515",
"format": "#,##0",
"publicationStatus": "Published"
},
{
"source": 264.0,
"value": 264.0,
"formatted": "264",
"format": "#,##0",
"publicationStatus": "Published"
},
{
"source": 254.0,
"value": 254.0,
"formatted": "254",
"format": "#,##0",
"publicationStatus": "Published"
},
{
"source": 455.0,
"value": 455.0,
"formatted": "455",
"format": "#,##0",
"publicationStatus": "Published"
}
]
}
]
}
я создал классы с использованием http://json2csharp.com/ и попробовали такие методы, как: -
RootObject ro = JsonConvert.DeserializeObject<RootObject>(json_data);
и
Value [] vo = JsonConvert.DeserializeObject<Value[]>(json_data);
и
dynamic result = JsonConvert.DeserializeObject(json_data);
также
JavaScriptSerializer jss = new JavaScriptSerializer();
Value [] thisval = jss.Deserialize<Value[]>(json_data);
Среди других. Что было бы правильным способом извлечения его информации в классы, чтобы я мог работать над ними. Примером вызова данных после десериализации будет полезно. Основные классы у меня есть
public class Value
{
public double source { get; set; }
public double value { get; set; }
public string formatted { get; set; }
public string format { get; set; }
public string publicationStatus { get; set; }
}
public class Row
{
public List<Value> values { get; set; }
}
public class RootObject
{
public Metadata metadata { get; set; }
public List<Column> columns { get; set; }
public List<Row> rows { get; set; }
}
Ну 'RootObject ро = JsonConvert.DeserializeObject (json_data)' работает для меня (используя пустые классы для 'метаданных 'и' Column') –
DavidG