我已经需要解析这个数据集,但我尝试了多种方法,但不起作用。
{"id":2,"area_id":"1","payment_term_id":"1","payment_type_id":"1","trade_channel_id":"1","salesman_id":1,"customer_name":"xxx","contact_number":"1231212","fax_number":"1231232","home_address":"asd","delivery_address":"dasd","email_address":"<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="a0d4c5d3d4e0c5c4c9d48ec3cfcd" rel="noreferrer noopener nofollow">[email protected]</a>","created_by":"4","updated_by":"4","is_active":"1","created_at":"2017-10-17 06:02:59","updated_at":"2017-10-17 06:13:22"}
我尝试了这个,但此错误表明
(1/1) 错误异常 尝试获取非对象的属性
$details = $request->get('details');
return $details->id;
我也尝试过这个
$details = $request->get('details');
return $details['id'];
(1/1) 错误异常 非法字符串偏移“id”
我使用的是 Laravel 5.4
最佳答案
由于数据来自请求,因此它是 JSON,而不是集合或对象。所以,你需要做这样的事情:
return json_decode($request->details)->id;
关于Laravel 数据集解析错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46806979/