我有这个功能:
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
这是什么回应?一个物体吧?为什么我只能将其压缩为变量并发送到视图?
非常感谢!
答案 0 :(得分:0)
您正在获得的响应是一个对象,为了在刀片中更好地使用,请尝试通过执行以下操作将其转换为数组:
$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字符串解析为数组即可。
P.S,如果对象响应上带有
-
符号(私有属性),请注意解析array
或json_encode
json_decode
的对象将不起作用 正确地