Ich automatisiere eine API. Ich möchte die JSON
Antwort deserialize, die ich bekomme, aber ich kann nicht herausfinden, wie man es macht. Dies ist die JSON
ich als Antwort erhalten:Deserialize Komplex JSON Ergebnis
{
"class": [
"Paged-Collection",
"Products"
],
"properties": {
"defaultPageSize": 10,
"skip": null,
"top": 10,
"totalRows": 2
},
"entities": [
{
"class": [
"Product"
],
"rel": [],
"properties": {
"Supplier": "Supplier1",
"Currency": "USD",
"ProductCode": "SomeCode1",
"price": 2
}
},
{
"class": [
"Product"
],
"rel": [],
"properties": {
"Supplier": "Supplier2",
"Currency": "USD",
"ProductCode": "SomeCode2",
"price": 73
}
},
],
"links": [
{
"rel": [
"self"
],
"href": "http://localhost...",
"method": "GET",
"title": null,
"type": null
}
]
}
von dem, was ich in anderen Beispielen gesehen habe die Deserialisierung nach unten kocht (wenn auch nicht sicher, ob das, was es ist), die genauen Daten strucutre, herauszufinden, aber ich habe einig (rauschen nicht nur sO Antwort auf) versucht, so ist dies mein letzter Versuch:
die Struktur, wie ich es sehe:
public class Data
{
List<string> @class { get; set; }
Dictionary<string, MetaData> properties { get; set; }
List<entities> entities { get; set; }
List<LinkFeed> links { get; set; }
}
public class MetaData
{
public int defaultPageSize { get; set; }
public string skip { get; set; }
public int top { get; set; }
public int totalRows { get; set; }
}
public class entities
{
public List<string> @class { get; set; }
public List<string> rel { get; set; }
public properties property { get; set; }
}
public class properties
{
public string Supplier { get; set; }
public string Currency { get; set; }
public string ProductCode { get; set; }
public string price { get; set; }
public double Price { get; set; }
}
public class LinkFeed
{
public List<string> rel { get; set; }
public string href { get; set; }
public string method { get; set; }
public string title { get; set; }
public string type { get; set; }
}
Und die tatsächliche Deserialisierung mit Newtonsoft.Json
:
var result = JsonConvert.DeserializeObject<Data>(data);
Und alles ist Null
..
Eigentlich die Daten, die ich wirklich interessiert bin ist, dass unter "entities"
aber ich weiß nicht, ob nur das Extrahieren tatsächlich einfacher sein wird, oder schwieriger.
Was bekommen Sie als Antwort? eine JSON-Zeichenfolge, eine JSON-Datei oder ein JSON-Objekt? – LordNeo
Objekt aber @CodingYoshi schon herausgefunden es – Leron