Fórum JSON COM DELPHI - DÚVIDA #623635
21/01/2025
0
Boa tarde, estou tentando ler os dados de um JSON que está num memo, mas sempre ocorre acess violation.
Alguém sabe me dizer onde estou errando? segue o código abaixo e o JSON.
[/code]{
"cart": [
{
"item": [
{
"id": 13,
"user_company_id": 1,
"company_id": 1,
"category_id": 4,
"name": "Coca-Cola Lata 350ml",
"description": "Coca-Cola Lata 350ml",
"img": "c66f1120ccd3d7803c061a44a8a130647d84efa3.jpg",
"price": "5.00",
"price_cost": "0.00",
"price_offer": "0.00",
"price_type": 0,
"item_type": 0,
"flavor_amount_min": 0,
"flavor_amount": 0,
"amount": -1,
"free_shipping": 0,
"external_code": "",
"is_unavailable_delivery": 0,
"unit_measure_type": 0,
"hidden": 0,
"position": 1
}
],
"note": "",
"amount": "7",
"price": 35,
"cartItemCode": "d570cb05af62f2e9c694"
},
{
"item": [
{
"id": 11,
"user_company_id": 1,
"company_id": 1,
"category_id": 4,
"name": "Sprite Lata 350ml",
"description": "Sprite Lata 350ml",
"img": "ce2b4744f52fa4a3c61723f02fd9d1542f88983d.jpg",
"price": "5.00",
"price_cost": "0.00",
"price_offer": "0.00",
"price_type": 0,
"item_type": 0,
"flavor_amount_min": 0,
"amount": -1,
"free_shipping": 0,
"external_code": "",
"is_unavailable_delivery": 0,
"unit_measure_type": 0,
"hidden": 0,
"position": 2
}
],
"note": "",
"amount": "9",
"price": 45,
"cartItemCode": "355ae4b6a41dd7d6b559"
}
],
"note": "",
"customer_name": "DANIEL",
"customer_phone_number": "(91) 98289-8056"
}[/code]
Alguém sabe me dizer onde estou errando? segue o código abaixo e o JSON.
[/code]{
"cart": [
{
"item": [
{
"id": 13,
"user_company_id": 1,
"company_id": 1,
"category_id": 4,
"name": "Coca-Cola Lata 350ml",
"description": "Coca-Cola Lata 350ml",
"img": "c66f1120ccd3d7803c061a44a8a130647d84efa3.jpg",
"price": "5.00",
"price_cost": "0.00",
"price_offer": "0.00",
"price_type": 0,
"item_type": 0,
"flavor_amount_min": 0,
"flavor_amount": 0,
"amount": -1,
"free_shipping": 0,
"external_code": "",
"is_unavailable_delivery": 0,
"unit_measure_type": 0,
"hidden": 0,
"position": 1
}
],
"note": "",
"amount": "7",
"price": 35,
"cartItemCode": "d570cb05af62f2e9c694"
},
{
"item": [
{
"id": 11,
"user_company_id": 1,
"company_id": 1,
"category_id": 4,
"name": "Sprite Lata 350ml",
"description": "Sprite Lata 350ml",
"img": "ce2b4744f52fa4a3c61723f02fd9d1542f88983d.jpg",
"price": "5.00",
"price_cost": "0.00",
"price_offer": "0.00",
"price_type": 0,
"item_type": 0,
"flavor_amount_min": 0,
"amount": -1,
"free_shipping": 0,
"external_code": "",
"is_unavailable_delivery": 0,
"unit_measure_type": 0,
"hidden": 0,
"position": 2
}
],
"note": "",
"amount": "9",
"price": 45,
"cartItemCode": "355ae4b6a41dd7d6b559"
}
],
"note": "",
"customer_name": "DANIEL",
"customer_phone_number": "(91) 98289-8056"
}[/code]
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | var js:TJSONObject; jDadosPedido:TJSONObject; jitem:TJSONObject; IDItem: string ; jArrItem:TJSONArray; i: integer ; begin js:=TJSONObject(TJSONObject . ParseJSONValue(Memo1 . Text)); if js<> nil then begin jDadosPedido:= TJSONObject(js . Values[ 'cart' ]); if jDadosPedido <> nil then begin jArrItem:=TJSONArray(jDadosPedido . Values[ 'item' ]); for i := 0 to jArrItem . Count- 1 do begin jitem:=TJSONObject(jArrItem . Items[i]); IDItem:= jitem . Values[ 'id' ].Value; ShowMessage(IDItem); end ; end ; js:= nil ; end ; end ; |

Daniel Ribeiro
Curtir tópico
+ 0
Responder
Clique aqui para fazer login e interagir na Comunidade :)