UWP Beispiel: Json Strings
Dieses Beispiel zeigt den Inhalt des UWP Samples: Json
Dabei wird der fogende String im Json Format analysiert
{ "id": "1146217767", "phone": null, "name": "Satya Nadella", "education": [ { "school": { "id": "204165836287254", "name": "Contoso High School" }, "type": "High School" }, { "school": { "id": "116138758396662", "name": "Contoso University" }, "type": "College" } ], "timezone": -8, "verified": true } |
Funktionsweise des Codes
Die Funktionsweise findet man in School.cs
Dabei wird aus dem Eingabestring ein JsonObject erstellt mit jsonObject.GetNamedObject(KeyName,null)
private const string idKey = "id"; private const string schoolKey = "school"; private const string nameKey = "name"; private const string typeKey = "type";
private string id; private string name; private string type;
public School() { Id = ""; Name = ""; Type = ""; }
public School(JsonObject jsonObject) { JsonObject schoolObject = jsonObject.GetNamedObject(schoolKey, null); if (schoolObject != null) { Id = schoolObject.GetNamedString(idKey, ""); Name = schoolObject.GetNamedString(nameKey, ""); } Type = jsonObject.GetNamedString(typeKey); } |
Man findet das UWP Json beispiel unter:
https://github.com/Microsoft/Windows-universal-samples/tree/master/Samples/Json
Unter Windows Universal Master Samples