【发布时间】:2016-12-30 10:43:03
【问题描述】:
我正在开发 laravel 应用程序,并将我的数据以 JSON 编码形式保存为
{"name":"Ali","email":"testdc@gamil.com"}
它在db文本字段中显示如上
在我的方法中,我得到的数据是
function users($id, Request $request)
{
$method = $request->method();
if($request->isMethod('GET')) {
$users = DB::table('user_settings')->select('notification_setting')->first();
print_r( $notification_smtp);
die;
return view('setting/user');
}
}
下面是上面代码的输出:
stdClass Object ( [notification_setting] => {"name":"Ali","email":"testdc@gamil.com"} )
如果我尝试解码它会给出错误,因为 json_decode 第二个参数应该是传递的字符串对象
我怎样才能得到这种格式的响应?
stdClass Object ( [name] => Ali [email] => test@gmail.com )
我怎样才能做到这一点?
【问题讨论】:
-
能否贴出用于解码 JSON 的语句?
-
它说 json_decode() 期望参数 1 是字符串,给定对象
-
是的,我们需要的是您在代码中用于解码 JSON 的方法/语句。
标签: php json laravel-5.3