How to read the data of a php object?

0

I am doing a project where I am consuming an object that they send me with a lot of data. in the following way

$cliente = new SoapClient("webservice");
$respuesta = $cliente->metodo();
var_dump($respuesta);

What the answer shows is something similar to this

object(stdClass)#2 (1) { ["metodoResultado"]=> string(3053)  "[{"cuenta":"001000","factura":"001062210","Voucher":"AdFc02_137582","fecha":"2017-02-20","fecha2":"2017-03-22","monto":9752},{"cuenta":"001000","factura":"001062222","Voucher":"AdFc02_137590","fecha":"2017-02-20","fecha2":"2017-03-22","monto":38913},{"cuenta":"001000","factura":"001062295","Voucher":"AdFc02_137650","fecha":"2017-02-21","fecha2":"2017-03-29",monto":59942},{"cuenta":"001000","factura":"001062305","Voucher":"AdFc02_137659","fecha":"2017-02-21","fecha2":"2017-03-29","monto":30690},{"cuenta":"001000","factura":"001062346","Voucher":"AdFc02_137696","fecha":"2017-02-21","fecha2":"2017-03-29","monto":28139},{"cuenta":"001000","factura":"001062744","Voucher":"AdFc02_138017","fecha":"2017-02-24","fecha2":"2017-03-29","monto":12537},{"cuenta":"001000","factura":"001062884","Voucher":"AdFc02_138134","fecha":"2017-02-28","fecha2":"2017-04-05","monto":77261},{"cuenta":"001000","factura":"001063072","Voucher":"AdFc02_138292","fecha":"2017-03-02","fecha2":"2017-04-05","monto":48295},{"cuenta":"001000","factura":"001063358","Voucher":"AdFc02_138525","fecha":"2017-03-06","fecha2":"2017-04-05","monto":75229},{"cuenta":"001000","factura":"001063413","Voucher":"AdFc02_138573","fecha":"2017-03-07","fecha2":"2017-04-12","monto":10363},{"cuenta":"001000","factura":"001063519","Voucher":"AdFc02_138658","fecha":"2017-03-07","fecha2":"2017-04-12","monto":4093},{"cuenta":"001000","factura":"001063868","Voucher":"AdFc02_138937","fecha":"2017-03-11","fecha2":"2017-04-12","monto":10353},{"cuenta":"001000","factura":"001063884","Voucher":"AdFc02_138953","fecha":"2017-03-13","fecha2":"2017-04-12","monto":50194},{"cuenta":"001000","factura":"001063916","Voucher":"AdFc02_138976","fecha":"2017-03-13","fecha2":"2017-04-12","monto":54132},{"cuenta":"001000","factura":"001064023","Voucher":"AdFc02_139063","fecha":"2017-03-14","fecha2":"2017-04-19","monto":6323},{"cuenta":"001000","factura":"001064114","Voucher":"AdFc02_139143","fecha":"2017-03-15","fecha2":"2017-04-19","monto":9560}]" 

This data that gives me results like working in php to get the information in rows and even separate the elements? I spend a few days trying many things, methods but still nothing. I can not understand how to make this work.

Thanks

    
asked by El Barto 23.05.2017 в 23:03
source

2 answers

0

The variable $ answer is effectively an object but within it is $ answer-> methodResult that is a string and to be able to work like json you should do this:

 $metodoResultado=json_decode($respuesta->metodoResultado);

But first I advise you to review the method that returns the object because you lack a quote in a "amount" and that can cause problems when decoding.

    
answered by 23.05.2017 в 23:25
0
Prueba con esto ya que es un Objeto :

    $cliente = new SoapClient("webservice");
    $respuesta = $cliente->metodo();
    $dato = var_dump($respuesta);
    $monto = $dato->monto;
    $Voucher = $dato->Voucher;
    $fecha= $dato->fecha;
    $fecha2= $dato->fecha2;
    
answered by 23.05.2017 в 23:37