使用 Laravel 从 json 中删除 "
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/32693688/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Remove " from json using laravel
提问by Harsh Makadia
Hello I wanted to know how to use blade variable in javascript. here is my query in laravel
您好,我想知道如何在 javascript 中使用刀片变量。这是我在 Laravel 中的查询
$users=json_encode(DB::table('ledger')->select('name','openingbalance')->get());
I'm trying to access this in my javascript file like shown below
我正在尝试在我的 javascript 文件中访问它,如下所示
var users ="{{ $users }}";
and I get output as shown below:
我得到如下所示的输出:
[
{"name":"Harsh","openingbalance":"5755.00"},
{"name":"Harh","openingbalance":"-12000.00"},
{"name":"gfgfhgf","openingbalance":"-333.00"}
]
I wanted to know how to remove " so i get a perfect json to use.
我想知道如何删除 " 以便我得到一个完美的 json 来使用。
回答by Joel Hinz
You're escaping the data with {{ }}
automatically in Laravel 5. Use {!! $users !!}
instead.
您{{ }}
在 Laravel 5 中使用自动转义数据。改为使用{!! $users !!}
。
回答by Mark Anthony
in new laravel version you can use now @json($users)
在新的 Laravel 版本中,您现在可以使用 @json($users)