PC SOFT

FORUMS PROFESSIONNELS
WINDEVWEBDEV et WINDEV Mobile

Accueil → WINDEV 23 → [WD22] Json Data
[WD22] Json Data
Débuté par Stefan Friedriszik, 14 juin 2018 07:32 - 3 réponses
Posté le 14 juin 2018 - 07:32
Hello forum members,
I have a disagreement with Thme JSON. Maybe someone can help me.

I do not receive any data with the following code

sJson is string ="{
"stichwort": "Street Food Festival",
"beginn": 1529154000,
"ende": 1529186100,
"zeitraum_bemerk": "",
"veranstaltung_id": 4650768,
"dienstnummer": "16",
"bemerkung": "An dieser Veranstaltung wird auch Bühnenprogramm stattfinden.\ \ ",
"eort": {
"freitext": "Bonnerstraße. in Lechenich",
"objekt": "Bonnerstraße. in Lechenich",
"gemeinde": null,
"land": null,
"strasse": null,
"hausnummer": null
},
"ansprech_name": "Philipp Uhle",
"ansprech_telnummer": "",
"hiorg_prim_orgid": 11581,
"hiorg_alle_orgid": [
{
"orgid": 11581,
"bezeichnung": "ASB Erft/Düren e.V."
}
],
"einsatzmittel_imeinsatz": [
{
"bezeichnung": "KTW2",
"anzahl_geplant": "1",
"mattypkunde": "Kraftfahrzeuge",
"mattyphiorg": "Kraftfahrzeuge",
"beschreibung": "",
"fugcode": "Sama/BRL/KTW2",
"koord_wache_lat": "",
"koord_wache_lon": "",
"hiorg_mat_inst_id": 1505058,
"hiorg_mat_id": 540000,
"hiorg_org_id": "11581"
},
{
"bezeichnung": "KTW3",
"anzahl_geplant": "1",
"mattypkunde": "Kraftfahrzeuge",
"mattyphiorg": "Kraftfahrzeuge",
"beschreibung": "Dempfer li/re erneuert, Bremsleitung erneuert, Motordischtung erneuert.",
"fugcode": "Sama/BRL/KTW3",
"koord_wache_lat": "",
"koord_wache_lon": "",
"hiorg_mat_inst_id": 1505060,
"hiorg_mat_id": 540002,
"hiorg_org_id": "11581"
},
{
"bezeichnung": "ELW 1-1",
"anzahl_geplant": "1",
"mattypkunde": "Kraftfahrzeuge",
"mattyphiorg": "Kraftfahrzeuge",
"beschreibung": "",
"fugcode": "Sama/BRL/ELW1",
"koord_wache_lat": "",
"koord_wache_lon": "",
"hiorg_mat_inst_id": 1505064,
"hiorg_mat_id": 540006,
"hiorg_org_id": "11581"
}
],
"einsatzkraefte_imeinsatz": {
"22480379": {
"nachname": "Helfer 1",
"vorname": "Patric",
"beschraenk": "",
"fw_qual": "",
"med_qual": "Rettungssanitäter",
"fuehr_qual": "Gruppenführer/in",
"bes_ausbild": "",
"tel_mobil": "",
"melder_nr": "",
"bemerk_einteilung": "",
"start": "",
"ende": "",
"hiorg_epos_id": 1227177,
"hiorg_ek_id": 230697,
"hiorg_org_id": 11581
},
"22921194": {
"nachname": "Helfer 2",
"vorname": "Rolf",
"beschraenk": "",
"fw_qual": "",
"med_qual": "Sanitätshelfer",
"fuehr_qual": "Gruppenführer/in",
"bes_ausbild": "",
"tel_mobil": "",
"melder_nr": "",
"bemerk_einteilung": "",
"start": "",
"ende": "",
"hiorg_epos_id": 1227180,
"hiorg_ek_id": 228253,
"hiorg_org_id": 11581
},
"25086025": {
"nachname": "Helfer 3",
"vorname": "Philipp",
"beschraenk": "",
"fw_qual": "",
"med_qual": "Rettungssanitäter",
"fuehr_qual": "Zugführer/in",
"bes_ausbild": "",
"tel_mobil": "",
"melder_nr": "Ja Swissphone",
"bemerk_einteilung": "",
"start": "",
"ende": "",
"hiorg_epos_id": 1227183,
"hiorg_ek_id": 61110,
"hiorg_org_id": 11581
},
"25681203": {
"nachname": "Helfer 4",
"vorname": "Ruben",
"beschraenk": "",
"fw_qual": "",
"med_qual": "Erste Hilfe",
"fuehr_qual": "Anwärter/in",
"bes_ausbild": "",
"tel_mobil": "",
"melder_nr": "",
"bemerk_einteilung": "",
"start": "",
"ende": "",
"hiorg_epos_id": 1227180,
"hiorg_ek_id": 716114,
"hiorg_org_id": 11581
},
"25875321": {
"nachname": "Helfer 5",
"vorname": "Fabian",
"beschraenk": "",
"fw_qual": "",
"med_qual": "Rettungshelfer",
"fuehr_qual": "Gruppenführer/in",
"bes_ausbild": "",
"tel_mobil": "",
"melder_nr": "",
"bemerk_einteilung": "",
"start": "",
"ende": "",
"hiorg_epos_id": 1227177,
"hiorg_ek_id": 61178,
"hiorg_org_id": 11581
},
"25894950": {
"nachname": "Helfer 6",
"vorname": "Lisa",
"beschraenk": "U18",
"fw_qual": "",
"med_qual": "Erste Hilfe",
"fuehr_qual": "Anwärter/in",
"bes_ausbild": "",
"tel_mobil": "",
"melder_nr": "",
"bemerk_einteilung": "",
"start": "",
"ende": "",
"hiorg_epos_id": 1227180,
"hiorg_ek_id": 716117,
"hiorg_org_id": 11581
},
"26047430": {
"nachname": "Helfer 7",
"vorname": "Kim Erich",
"beschraenk": "",
"fw_qual": "",
"med_qual": "Rettungshelfer",
"fuehr_qual": "Anwärter/in",
"bes_ausbild": "",
"tel_mobil": "",
"melder_nr": "",
"bemerk_einteilung": "",
"start": "",
"ende": "",
"hiorg_epos_id": 1227177,
"hiorg_ek_id": 269419,
"hiorg_org_id": 11581
},
"26069867": {
"nachname": "Helfer 8",
"vorname": "Stefan",
"beschraenk": "",
"fw_qual": "",
"med_qual": "Santätsdienst",
"fuehr_qual": "Leiter Rettungshunde",
"bes_ausbild": "",
"tel_mobil": "",
"melder_nr": "Ja Swissphone",
"bemerk_einteilung": "",
"start": "",
"ende": "",
"hiorg_epos_id": 1227183,
"hiorg_ek_id": 61040,
"hiorg_org_id": 11581
}
},
"einsatzpositionen": [
{
"hiorg_epos_id": 1227177,
"bezeichnung": "SAMA BRL KTW3"
},
{
"hiorg_epos_id": 1227180,
"bezeichnung": "SAMA BRL KTW2"
},
{
"hiorg_epos_id": 1227183,
"bezeichnung": "SAMA BRL ELW 1-1"
}
],
"status": "OK",
"apiversion": "2.0",
"timestamp": 1528953042
}"

vJson is Variant = JSONToVariant(sJson)

FOR n = 1 _TO_ vJson.einsatzkraefte_imeinsatz..Occurrence
TableAddLine (TABLE_Personal, vJson.einsatzkraefte_imeinsatz [n] .nachname)
END


what am I doing wrong?

Best regards and thank you in advance
Stefan
Posté le 14 juin 2018 - 13:18
Hi Stefan

You are forgetting a level...
Inside "einsatzkraefte_imeinsatz", you have several sublevels ("22480379", "22921194", etc...

the variable you are trying to reach (nachname) is nested inside each of those...

So your loop should be to first get the value of each "einsatzkraefte_imeinsatz", put it inside a second level variant, then get your value

You can see that quite clearly by putting yor json string in notepad++ and Fold/unfold each level in turn... For each level you have to unfold here, you need some code.

Best regards
Posté le 14 juin 2018 - 14:09
Hi Fabrice,

Many thanks. Sometimes you do not see the forest for the trees.


Regards
Stefan
Posté le 14 juin 2018 - 23:31
Hi Stefan,

What Fabrice wrote but don't need another variant

vJson is Variant = JSONToVariant(sJSON) FOR EACH ek OF vJson.einsatzkraefte_imeinsatz..Member TableAddLine (TABLE_Personal, {"vJson.einsatzkraefte_imeinsatz."+ek..Name+".nachname",indVariable}) END