【发布时间】:2018-07-18 05:54:46
【问题描述】:
我在客户端有这个 JSON 对象:
我将该 ajax JSON 对象发送到控制器,例如:
$.ajax({
type: "GET",
url: url,
data: {sToken: token.id, reference: r, newserials: jsonObj},
dataType: "json",
success: function(data)
{ ... ... etc.
然后在 Controller 我用:
$newserials = $request->newserials;
我现在需要将$newserials 转换为雄辩的对象,所以我想使用$newserials 像:
foreach ($newserials as $new) {
$serial = $new->serial;
$pin = $new->pin;
}
那么我如何才能将 JSON 转换为 eloquent 并以上述方式使用?
该应用程序已上线,我无法对此进行测试,因此我为这些琐碎的问题寻求帮助。对此感到抱歉。
更新: 我以字符串形式发送新闻:
var newserials = JSON.stringify(jsonObj);
其余代码按照您的建议:
$newserials = json_decode(json_encode($request->newserials));
但现在我得到了错误:
试图在 foreach 循环中获取非对象的属性!
【问题讨论】: