laravel json_encode 返回 "

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/33993211/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 12:45:09  来源:igfitidea点击:

json_encode returns "

javascriptphplaravelchart.js

提问by Orion

I am trying to build a chart with Chart.js using laravel. The json_encode function returns the string with & quot; instead of " that Chart.js cannot recognize. Tried the htmlspecialchars_decode() with no luck. Is there any other workaround ? Please help.

我正在尝试使用 laravel 使用 Chart.js 构建图表。json_encode 函数返回带有 & quot; 的字符串。而不是 Chart.js 无法识别的“。尝试 htmlspecialchars_decode() 没有运气。还有其他解决方法吗?请帮忙。

This is the laravel code

这是laravel的代码

  labels: {{  htmlspecialchars_decode(json_encode($sm_names)) }},
                datasets: [{
                data: {{  str_replace('"','',json_encode($sm_totals))}},

and this is how it is rendered in javascript:

这就是它在 javascript 中的呈现方式:

labels: ["John","Mercy ","Gary"],
                datasets: [{
                data: [425000,470000,10000],

回答by KAndy

If you use blade, try {!! json_encode($sm_names) !!}

如果您使用刀片,请尝试 {!! json_encode($sm_names) !!}