如何阅读 php 中的 JsonResponse
How to read JsonResponse in php
如何从此处获取 ID
JsonResponse {#457 ▼
#data: "{"bill":{"id":11,"invoice_no":"9m36r9_1459170388239"}}"
#callback: null
}
我从这个 laravel 代码得到这个输出
return Response::json($response);
我试过json_decode
但在这里不起作用,出现空白输出。
感谢您的帮助。
试试这个,它对我有用:
$.ajax({
type: "POST",
url: url,
data: {
...
},
success: function (data) {
alert(data.bill.id)
},
error: function (err) {
}
});
如果这不起作用,请告诉我。
这样试试
$jsonResponse = Response::json([
'id' => 1,
'test' => 'test'
]);
$content = $jsonResponse->getContent();
$array = json_decode($content, true);
$id = $array['id']
这对我有用,使用 getData()。 Laravel 5.7.
$jsonResponse = Response::json([
'id' => 1,
'test' => 'test'
]);
$content = $jsonResponse->getData();
$id = $content->id;
如何从此处获取 ID
JsonResponse {#457 ▼
#data: "{"bill":{"id":11,"invoice_no":"9m36r9_1459170388239"}}"
#callback: null
}
我从这个 laravel 代码得到这个输出
return Response::json($response);
我试过json_decode
但在这里不起作用,出现空白输出。
感谢您的帮助。
试试这个,它对我有用:
$.ajax({
type: "POST",
url: url,
data: {
...
},
success: function (data) {
alert(data.bill.id)
},
error: function (err) {
}
});
如果这不起作用,请告诉我。
这样试试
$jsonResponse = Response::json([
'id' => 1,
'test' => 'test'
]);
$content = $jsonResponse->getContent();
$array = json_decode($content, true);
$id = $array['id']
这对我有用,使用 getData()。 Laravel 5.7.
$jsonResponse = Response::json([
'id' => 1,
'test' => 'test'
]);
$content = $jsonResponse->getData();
$id = $content->id;