繁体   English   中英

SOAP响应。 怎么处理呢?

[英]SOAP response. How to handle it?

我有这个功能:

public function index(Request $request)
    {
        try {
            self::setWsdl('http://000.000.00.00/SomeServices.asmx?WSDL');
            $this->service = InstanceSoapClient::init();
            $params = [
                'sGrupo' => "0".$request->sGrupo,
                'iCota' => $request->iCota,
                'iIdERP' => $request->iIdERP
            ];
            $response = $this->service->ROS_ExtratoContaCorrente($params);
            return view('layouts.extrato', compact('response'));
        } catch (\Exception $e) {
            return $e->getMessage();
        }
    }

和结果使用

dd($response);

我得到:

{#198 ▼
  +"ExtratoContaCorrente": {#199 ▼
    +"NOME-CLIENTE": "JON DOE"
    +"CODIGO-GRUPO": "06275"
    +"NUMERO-COTA": 45
    +"NOME-LOGRADOURO": "STREET JUNIOR"
    +"NUMERO-LOGRADOURO": "519"
    +"BAIRRO": "PRESIDENTE ROOSEVELT"
    +"CIDADE": "UBERLANDIA"
    +"UF": "MG"
    +"CEP": "00000000"
    +"NUMERO-TELEFONE": "000 000000000"
    +"CODIGO-BEM": "6156"
    +"VALOR-BEM": 12000.0
    +"PERC-TOTAL-PAGO": 31.7396
    +"VALOR-QUITACAO": 10090.62
    +"PERC-TOAL-PAGAR": 0.5546
    +"PARCELAS-PAGAS": {#205 ▶}
    +"PARCELAS-PENDENTES": {#207 ▶}
    +"PROXIMA-ASSEMBLEIA": {#209 ▶}
    +"RESULT-ULTIMA-ASSEMB": {#210 ▶}
    +"CODIGO-RETORNO": 0
    +"DESCRICAO-RETORNO": ""
  }
}

如何处理这些数据以呈现在视图上? 现在,我收到此错误:这是我的观点:

@extends('app')
@section('content')

@endsection
@section('scripts')
<script>
    var vue = new Vue({
        el: '#app',
        data: {
            response: {!! $response !!}
        }
    })
</script>
ErrorException (E_ERROR)
Object of class stdClass could not be converted to string (View: /Users/marcellopato/Sites/primorossicontemplado/resources/views/layouts/extrato.blade.php)
Previous exceptions
Object of class stdClass could not be converted to string

这是什么反应? 一个物体吧? 为什么我只能将其压缩为变量并发送到视图?

非常感谢!

您得到的响应是一个对象,为了更好地在刀片中使用,请尝试执行以下操作以将其转换为数组:

$response = json_decode(json_encode($response), true);

要么

$response = (array) $response;

在传递给视图之前:

public function index(Request $request)
{
    try 
    {

        self::setWsdl('http://000.000.00.00/SomeServices.asmx?WSDL');

        $this->service = InstanceSoapClient::init();

        $params        = [
            'sGrupo' => "0" . $request->sGrupo,
            'iCota'  => $request->iCota,
            'iIdERP' => $request->iIdERP,
        ];

        $response = $this->service->ROS_ExtratoContaCorrente($params);

        $response = json_decode(json_encode($response), true);

        return view('layouts.extrato', compact('response'));

    } catch (\Exception $e) {

        return $e->getMessage();
    }
}

说明:

给定对象的每个属性都有一个前缀+ ,这意味着这些属性是公共属性,因此在将其强制转换为json字符串然后将json字符串解析为数组之前可以使用。

PS,如果对象响应具有-签名(私有属性),请注意将对象解析为arrayjson_encode json_decode将无法正常工作。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM