2016-12-30 64 views
1

我的工作laravel应用程序,我用JSON编码格式进行保存我的数据无法从数据库数据进行解码(PHP LAravel 5.3)

{"name":"Ali","email":"[email protected]"} 

它上面的显示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":"[email protected]"}) 

如果我尝试解码它,它提供了一个错误的json_decode第二个参数应字符串对象传递

我怎样才能得到这种格式的响应?

stdClass Object ([name] => Ali [email] => [email protected]) 

我怎么可能做到这一点?

+0

你可以发布使用JSON解码的声明? – Samir

+0

它表示为json_decode()期望参数1是字符串,对象是 –

+0

是的,我们需要的是您在代码中用于解码JSON的方法/语句。 – Samir

回答

1

尝试print_r(json_decode($notification_smtp->notification_setting));

0

您是否试过序列化?像得到一个tmp变量与解析对象

//your code 
$users = DB::table('user_settings')->select('notification_setting')->first(); 
       print_r($notification_smtp); 
       die; 
//try this 
$tmp = (string) $user; 
dd($tmp); 

如果没有帮助,请阅读laravel doc,它真的很好。

Laravel Serialization

如果仍然没有帮助你,谷歌的序列化和反序列化)