Tengo este Json que recibo de un Api Rest
- Code: Select all Expand view
- {"order": {"id": "196", "nit": null, "name": "Jhonatan Valero", "email": "jhonatan.valero@omni.pro", "items": [{"sku": "MUR0491", "name": "Block Tapado Liviano de 14 de 14x19x39cm (UN) 25kg/cmu00b2", "price": 3.09, "seller": "", "source": "Aceros de Guatemala", "quantity": 14, "entity_id": "235", "total_price": 43.26, "order_item_id": "301", "shipping_method": "Entrega por un tercero"}, {"sku": "MUR0491", "name": "Block Tapado Liviano de 14 de 14x19x39cm (UN) 25kg/cmu00b2", "price": 3.09, "seller": "", "source": "Aceros de Guatemala", "quantity": 13, "entity_id": "235", "total_price": 40.17, "order_item_id": "302", "shipping_method": "Retiro en tienda"}, {"sku": "MUR0491", "name": "Block Tapado Liviano de 14 de 14x19x39cm (UN) 25kg/cmu00b2", "price": 3.09, "seller": "", "source": "Tiendas Super", "quantity": 5, "entity_id": "235", "total_price": 15.45, "order_item_id": "303", "shipping_method": "Retiro en tienda"}], "created_at": "2022-10-20 22:09:00", "customer_id": "112", "person_type": 0, "increment_id": "4000000196", "legalAddress": {"city": null, "region": "Alta Verapaz", "street": "Cll 100", "country": "GT", "zip_code": "16013", "telephone": "31264587", "municipality": "Chisec"}, "razon_social": "Mi empresa", "taxes_amount": 0, "total_amount": 98.88, "payment_method": "banktransfer", "discount_amount": 0, "shippingAddress": {"city": null, "name": "Jhonatan 2", "region": "Chimaltenango", "street": "Cll 102", "country": "GT", "zip_code": "16013", "telephone": "31264587", "municipality": "Chimaltenango"}, "shipping_amount": 0, "nombre_comercial": "Mi empresa", "nombre_propietario": " ", "representante_legal": " "}}
Y estoy intentando encontrar sus valores, por lo que he probado convertirlo a Hash, pero no logro obtener ningun valor.
He probado de esta forma:
- Code: Select all Expand view
TEXT INTO cJs
{"order": {"id": "196", "nit": null, "name": "Jhonatan Valero", "email": "jhonatan.valero@omni.pro", "items": [{"sku": "MUR0491", "name": "Block Tapado Liviano de 14 de 14x19x39cm (UN) 25kg/cmu00b2", "price": 3.09, "seller": "", "source": "Aceros de Guatemala", "quantity": 14, "entity_id": "235", "total_price": 43.26, "order_item_id": "301", "shipping_method": "Entrega por un tercero"}, {"sku": "MUR0491", "name": "Block Tapado Liviano de 14 de 14x19x39cm (UN) 25kg/cmu00b2", "price": 3.09, "seller": "", "source": "Aceros de Guatemala", "quantity": 13, "entity_id": "235", "total_price": 40.17, "order_item_id": "302", "shipping_method": "Retiro en tienda"}, {"sku": "MUR0491", "name": "Block Tapado Liviano de 14 de 14x19x39cm (UN) 25kg/cmu00b2", "price": 3.09, "seller": "", "source": "Tiendas Super", "quantity": 5, "entity_id": "235", "total_price": 15.45, "order_item_id": "303", "shipping_method": "Retiro en tienda"}], "created_at": "2022-10-20 22:09:00", "customer_id": "112", "person_type": 0, "increment_id": "4000000196", "legalAddress": {"city": null, "region": "Alta Verapaz", "street": "Cll 100", "country": "GT", "zip_code": "16013", "telephone": "31264587", "municipality": "Chisec"}, "razon_social": "Mi empresa", "taxes_amount": 0, "total_amount": 98.88, "payment_method": "banktransfer", "discount_amount": 0, "shippingAddress": {"city": null, "name": "Jhonatan 2", "region": "Chimaltenango", "street": "Cll 102", "country": "GT", "zip_code": "16013", "telephone": "31264587", "municipality": "Chimaltenango"}, "shipping_amount": 0, "nombre_comercial": "Mi empresa", "nombre_propietario": " ", "representante_legal": " "}}
ENDTEXT
cHs:={=>}
hb_jsonDecode(cJs,@cHs)
? cHs['order']['id']
Y me da: Error BASE/1132 Error de rango: acceso al array
O bien:
- Code: Select all Expand view
TEXT INTO cJs
{"order": {"id": "196", "nit": null, "name": "Jhonatan Valero", "email": "jhonatan.valero@omni.pro", "items": [{"sku": "MUR0491", "name": "Block Tapado Liviano de 14 de 14x19x39cm (UN) 25kg/cmu00b2", "price": 3.09, "seller": "", "source": "Aceros de Guatemala", "quantity": 14, "entity_id": "235", "total_price": 43.26, "order_item_id": "301", "shipping_method": "Entrega por un tercero"}, {"sku": "MUR0491", "name": "Block Tapado Liviano de 14 de 14x19x39cm (UN) 25kg/cmu00b2", "price": 3.09, "seller": "", "source": "Aceros de Guatemala", "quantity": 13, "entity_id": "235", "total_price": 40.17, "order_item_id": "302", "shipping_method": "Retiro en tienda"}, {"sku": "MUR0491", "name": "Block Tapado Liviano de 14 de 14x19x39cm (UN) 25kg/cmu00b2", "price": 3.09, "seller": "", "source": "Tiendas Super", "quantity": 5, "entity_id": "235", "total_price": 15.45, "order_item_id": "303", "shipping_method": "Retiro en tienda"}], "created_at": "2022-10-20 22:09:00", "customer_id": "112", "person_type": 0, "increment_id": "4000000196", "legalAddress": {"city": null, "region": "Alta Verapaz", "street": "Cll 100", "country": "GT", "zip_code": "16013", "telephone": "31264587", "municipality": "Chisec"}, "razon_social": "Mi empresa", "taxes_amount": 0, "total_amount": 98.88, "payment_method": "banktransfer", "discount_amount": 0, "shippingAddress": {"city": null, "name": "Jhonatan 2", "region": "Chimaltenango", "street": "Cll 102", "country": "GT", "zip_code": "16013", "telephone": "31264587", "municipality": "Chimaltenango"}, "shipping_amount": 0, "nombre_comercial": "Mi empresa", "nombre_propietario": " ", "representante_legal": " "}}
ENDTEXT
cHs:={=>}
hb_jsonDecode(cJs,@cHs)
xbrowse( cHs )
No obtengo nigun valor con xBrowse()
Alguien me puede indicar como puedo tratar este JSon por favor?
Saludos cordiales.
Carlos