Foros del Web » Programando para Internet » PHP »

Leer un Json con "0" (Cero)

Estas en el tema de Leer un Json con "0" (Cero) en el foro de PHP en Foros del Web. Hola, tengo un Json que es el siguiente en una variable, todo va bien: {"OrderNumber":"1822002","OrderDate":"2019-06-20T00:00:00","Customer":{"CustomerId":"ABC02820"," Name":"EJEMPLO S. A.","Company":{"Id":"XAA","Name":"Ejemplo"},"Count ry":{"Id":"RR","Name":"Ejemplo"},"Currency":{"Curr encyId":"dor","CurrencyCode":null,"Description":nu ll,"Symbol":null,"UsExchangeRate":null}},"Customer OrderNumber":null,"StoreOrder":{"StoreId":"ejemmpl o","StoreOrderNumber":"81-ABC131","Customer":null,"Billing":null,"Shipping": null,"DeliveryType":null,"CrossReferenceKey":null} ,"Items":[{"CouponCodes":null,"StoreItemId":null,"LineNumber ...
  #1 (permalink)  
Antiguo 20/06/2019, 16:42
 
Fecha de Ingreso: abril-2011
Ubicación: Az, EEUU
Mensajes: 6
Antigüedad: 13 años
Puntos: 0
Leer un Json con "0" (Cero)

Hola, tengo un Json que es el siguiente en una variable, todo va bien:

{"OrderNumber":"1822002","OrderDate":"2019-06-20T00:00:00","Customer":{"CustomerId":"ABC02820"," Name":"EJEMPLO S. A.","Company":{"Id":"XAA","Name":"Ejemplo"},"Count ry":{"Id":"RR","Name":"Ejemplo"},"Currency":{"Curr encyId":"dor","CurrencyCode":null,"Description":nu ll,"Symbol":null,"UsExchangeRate":null}},"Customer OrderNumber":null,"StoreOrder":{"StoreId":"ejemmpl o","StoreOrderNumber":"81-ABC131","Customer":null,"Billing":null,"Shipping": null,"DeliveryType":null,"CrossReferenceKey":null} ,"Items":[{"CouponCodes":null,"StoreItemId":null,"LineNumber ":1,"Product":{"Sku":"AC122KLX16","Mpn":"KFM-565","Description":"una descripción bastante grande, de mucho texto, hasta 800 x 600 mm","Type":"Physical","Manufacturer":{"Manufacture rId":"acv","Description":"Accvent"},"Brand":{"Manu facturerId":"acv","BrandId":"klx","Description":"K lip Xtreme"},"Category":{"CategoryId":"mon","Descripti on":"Monitores & Proyectores","Subcategories":[{"CategoryId":"mon.monacc","Description":"Accesori os","Subcategories":[]}]},"Freight":null,"ProductLine":"Klip Xtreme","Model":"KFM-565"},"Quantity":1,"LocationId":"xgt1","UnitPrice" :{"Amount":11.3996,"HomeAmount":null,"Currency":nu ll},"ExtendedPrice":{"Amount":11.4,"HomeAmount":nu ll,"Currency":null},"Comments":null,"Components":[],"ParentSku":null,"Discounts":{"Amount":null,"Home Amount":null,"Currency":null}}],"ItemCount":1,"CouponCodes":null,"TaxRegistration Number":null,"InvoiceRequested":false,"ReceiveInvo iceByMail":false,"Payments":null,"Shipments":null, "OnHold":true,"TotalPaymentsAmount":0.0,"Status":{ "StatusCode":"1","Description":"Open"},"Currency": {"CurrencyId":"dor","CurrencyCode":"$$$","Descript ion":"Dólares","Symbol":"$","UsExchangeRate":null} ,"Comments":null,"TaxRate":1.0,"OtherFees":"","Sub total":{"Amount":57.4,"HomeAmount":57.4,"Currency" :null},"Discounts":{"Amount":0.0,"HomeAmount":null ,"Currency":null},"Tax":{"Amount":6.89,"HomeAmount ":6.89,"Currency":null},"ShippingFee":{"Amount":0. 0,"HomeAmount":null,"Currency":null},"Total":{"Amo unt":57.4,"HomeAmount":57.4,"Currency":null},"Tag" :null,"PrintedInvoiceNumber":""}


He tomado las variables que necesito, así:

$NumeroOrden = Trim($info->OrderNumber);
$FechaOrden = Trim($info->OrderDate);
$DocumentoWay = Trim($info->StoreOrder->StoreOrderNumber);
$Producto = Trim($info->Items->0->Product->Description);

Pero $Producto, no lo puedo tomar, pues ese "Cero" me da error "->0", como puedo tomar la "Description" de éste Json ????? Que sintaxis puedo usar ??????

Gracias por su ayuda.

Saludos.
  #2 (permalink)  
Antiguo 20/06/2019, 21:37
Avatar de Triby
Mod on free time
 
Fecha de Ingreso: agosto-2008
Ubicación: $MX->Gto['León'];
Mensajes: 10.106
Antigüedad: 15 años, 8 meses
Puntos: 2237
Respuesta: Leer un Json con "0" (Cero)

Haz un var_dump o print_r de $info->items, ahí podrás ver cómo acceder, de lo contrario pega aquí el resultado para ver si podemos ayudar.
__________________
- León, Guanajuato
- GV-Foto
  #3 (permalink)  
Antiguo 21/06/2019, 07:22
Avatar de vb2005  
Fecha de Ingreso: noviembre-2005
Ubicación: Paderborn - Alemania
Mensajes: 566
Antigüedad: 18 años, 5 meses
Puntos: 24
Respuesta: Leer un Json con "0" (Cero)

Primero el JSON que enviaste tiene errores, pero si no entiendo mal tu problema, lo puedes hacer de la siguiente forma:

Código PHP:
Ver original
  1. $info->Items[0]->Product->Description
__________________
www.marcher.com.uy - Web personal
Nerd's Corner - Desarrollo de software a medida

Etiquetas: json
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 16:28.