Hallo allen,
Ik ben bezig met een koppeling met de Magento 2.0 webshop. Hier wil ik de relaties gegevens uithalen.
Dit heb ik werkende, en ik krijg JSON data als resultaat voor het adres veld terug.
Deze JSON data ziet er als volgt uit:
Code:
{"_embedded":{"addresses":
[
{
"id": 2,
"customer_id": 3,
"region": {
"region_code": "Nederland",
"region": "Nederland",
"region_id": 0
},
"region_id": 0,
"country_id": "NL",
"street": [
"Adres met nummer"
],
"company": "Bedrijf",
"telephone": "1234567890",
"postcode": "1234 AA",
"city": "Plaats",
"firstname": "Voornaam'",
"lastname": "Achternaam",
"default_shipping": true,
"default_billing": true
}
]
}
}
Deze lees ik vervolgens uit met onderstaande code. Dit werkt goed voor alle JSON items, behalve het adres veld(street). Dit is een array, maar hoe lees ik deze nu correct uit?
Code:
Try // JSON
LJSONBytes := TEncoding.ANSI.GetBytes(sAdresJSON);
LJSONSObj := TJSONObject.ParseJSONValue(LJSONBytes, 0);
if LJSONSObj <> nil then begin
try
LJSONArray := LJSONSObj.GetValue<TJSONArray>('_embedded.addresses');
For LJSONValue In LJSONArray Do begin
iId := LJSONValue.GetValue<integer>('id');
iRelatieId := LJSONValue.GetValue<integer>('customer_id');
sRelatie := LJSONValue.GetValue<string>('company');
sVoornaam := LJSONValue.GetValue<string>('firstname');
sAchternaam := LJSONValue.GetValue<string>('lastname');
sAdres := LJSONValue.GetValue<string>('street');
sPostcode := LJSONValue.GetValue<string>('postcode');
sPlaats := LJSONValue.GetValue<string>('city');
sLand := LJSONValue.GetValue<string>('country_id');
sTelefoon := LJSONValue.GetValue<string>('telephone');
end;
finally
LJSONSObj.Free;
end; // End Try/Finally
end; // End if LJSONSObj <> nil
Except
on E: Exception Do
Begin
Application.MessageBox(PChar('Letop! Exception opgetreden!' +#13#10+ #13#10 +
'Fout: '+ E.ClassName +#13#10+ #13#10 + E.Message), 'Fout bij aanroepen Unit: Inlezen adressen', MB_ICONINFORMATION);
End;
End; // End Try JSON
Wie kan mij in de goede richting sturen
Bookmarks