Php htmlspecialchars()要求参数1为字符串,数组以Laravel形式给出

Php htmlspecialchars()要求参数1为字符串,数组以Laravel形式给出,php,html,laravel,laravel-5.3,laravel-blade,Php,Html,Laravel,Laravel 5.3,Laravel Blade,我的Laravelblade模板中出现此错误 htmlspecialchars()要求参数1为字符串,数组给定 我尝试在blade模板中将数组转换为字符串 这是代码 <script> var value = {{ $sliderImageDataArray }}.toString() window.MedicPressSliderCaptions = value; </script> [{"title":"First title","text":"<

我的
Laravel
blade模板中出现此错误

htmlspecialchars()要求参数1为字符串,数组给定

我尝试在blade模板中将数组转换为字符串

这是代码

<script>
    var value = {{ $sliderImageDataArray }}.toString()
    window.MedicPressSliderCaptions = value;
</script>
[{"title":"First title","text":"<p><span id=\"hs_cos_wrapper_module_1498510869515998\" class=\"hs_cos_wrapper hs_cos_wrapper_widget_container hs_cos_wrapper_type_widget_container\" data-hs-cos-general-type=\"widget_container\" data-hs-cos-type=\"widget_container\">First title<\\\/span><\\\/p>\n<p><a class=\"btn  btn-secondary\" href=\"http:\\\/\\\/localhost\\\/sencare\\\/book-appoinment\\\/\" target=\"_self\">  Make An Appointment <\\\/a>\\u00a0<a class=\"btn  btn-light\" href=\"http:\\\/\\\/localhost\\\/sencare\\\/our-doctors\\\/\" target=\"_self\"> Our Doctors<\\\/a><\\\/p>\n","is_video":false},{"title":"Second","text":"<p><span id=\"hs_cos_wrapper_module_1498510869515998\" class=\"hs_cos_wrapper hs_cos_wrapper_widget_container hs_cos_wrapper_type_widget_container\" data-hs-cos-general-type=\"widget_container\" data-hs-cos-type=\"widget_container\">Second<\\\/span><\\\/p>\n<p><a class=\"btn  btn-secondary\" href=\"http:\\\/\\\/localhost\\\/sencare\\\/book-appoinment\\\/\" target=\"_self\">  Make An Appointment <\\\/a>\\u00a0<a class=\"btn  btn-light\" href=\"http:\\\/\\\/localhost\\\/sencare\\\/our-doctors\\\/\" target=\"_self\"> Our Doctors<\\\/a><\\\/p>\n","is_video":false}]

{{}
将由刀片模板引擎转换为
echo()
。您试图将数组作为字符串进行回显

您可以将其转换为JSON:

var value = '{{ json_encode($sliderImageDataArray) }}';
如果是Laravel系列或模型:

var value = '{{ $sliderImageData->toJson() }}';

第一个对我来说是正确的。现在没有错误。但我还没有得到目标result@raff你的问题是关于错误的。如果您想将数据转换为某种格式,您应该描述如何准确地获取数据以及希望得到什么样的结果。这是正确的答案,但是blade engine将
{{$x}
替换为
而不是