Laravel - json_encode() does not work

Asked

Viewed 22 times

-1

Bring to Laravel in array format.

[compacto] => {"version":"4.5.0","objects":[{"type":"group","version":"4.5.0","originX":"left","originY":"top","left":567,"top":313,"width":48,"height":48,"fill":"rgb(0,0,0)","stroke":null,"strokeWidth":0,"strokeDashArray":null,"strokeLineCap":"butt","strokeDashOffset":0,"strokeLineJoin":"miter","strokeUniform":false,"strokeMiterLimit":4,"scaleX":1,"scaleY":1,"angle":0,"flipX":false,"flipY":false,"opacity":1,"shadow":null,"visible":true,"backgroundColor":"","fillRule":"nonzero","paintFirst":"fill","globalCompositeOperation":"source-over","skewX":0,"skewY":0,"objects":[{"type":"image","version":"4.5.0","originX":"left","originY":"top","left":-24,"top":-24,"width":48,"height":48,"fill":"rgb(0,0,0)","stroke":null,"strokeWidth":0,"strokeDashArray":null,"strokeLineCap":"butt","strokeDashOffset":0,"strokeLineJoin":"miter","strokeUniform":false,"strokeMiterLimit":4,"scaleX":1,"scaleY":1,"angle":0,"flipX":false,"flipY":false,"opacity":1,"shadow":null,"visible":true,"backgroundColor":"","fillRule":"nonzero","paintFirst":"fill","globalCompositeOperation":"source-over","skewX":0,"skewY":0,"cropX":0,"cropY":0,"src":"http://127.0.0.1:8000/assets/img/icone_marker.png","crossOrigin":null,"filters":[]},{"type":"text","version":"4.5.0","originX":"left","originY":"top","left":-14,"top":-19,"width":24.01,"height":40.68,"fill":"black","stroke":null,"strokeWidth":1,"strokeDashArray":null,"strokeLineCap":"butt","strokeDashOffset":0,"strokeLineJoin":"miter","strokeUniform":false,"strokeMiterLimit":4,"scaleX":1,"scaleY":1,"angle":0,"flipX":false,"flipY":false,"opacity":1,"shadow":null,"visible":true,"backgroundColor":"","fillRule":"nonzero","paintFirst":"fill","globalCompositeOperation":"source-over","skewX":0,"skewY":0,"text":"1","fontSize":36,"fontWeight":"normal","fontFamily":"Arial Black","fontStyle":"normal","lineHeight":1.16,"underline":false,"overline":false,"linethrough":false,"textAlign":"left","textBackgroundColor":"","charSpacing":0,"path":null,"direction":"ltr","styles":{}}]},{"type":"group","version":"4.5.0","originX":"left","originY":"top","left":430,"top":844,"width":59.02,"height":48,"fill":"rgb(0,0,0)","stroke":null,"strokeWidth":0,"strokeDashArray":null,"strokeLineCap":"butt","strokeDashOffset":0,"strokeLineJoin":"miter","strokeUniform":false,"strokeMiterLimit":4,"scaleX":1,"scaleY":1,"angle":0,"flipX":false,"flipY":false,"opacity":1,"shadow":null,"visible":true,"backgroundColor":"","fillRule":"nonzero","paintFirst":"fill","globalCompositeOperation":"source-over","skewX":0,"skewY":0,"objects":[{"type":"image","version":"4.5.0","originX":"left","originY":"top","left":-29.51,"top":-24,"width":48,"height":48,"fill":"rgb(0,0,0)","stroke":null,"strokeWidth":0,"strokeDashArray":null,"strokeLineCap":"butt","strokeDashOffset":0,"strokeLineJoin":"miter","strokeUniform":false,"strokeMiterLimit":4,"scaleX":1,"scaleY":1,"angle":0,"flipX":false,"flipY":false,"opacity":1,"shadow":null,"visible":true,"backgroundColor":"","fillRule":"nonzero","paintFirst":"fill","globalCompositeOperation":"source-over","skewX":0,"skewY":0,"cropX":0,"cropY":0,"src":"http://127.0.0.1:8000/assets/img/icone_marker.png","crossOrigin":null,"filters":[]},{"type":"text","version":"4.5.0","originX":"left","originY":"top","left":-19.51,"top":-19,"width":48.02,"height":40.68,"fill":"black","stroke":null,"strokeWidth":1,"strokeDashArray":null,"strokeLineCap":"butt","strokeDashOffset":0,"strokeLineJoin":"miter","strokeUniform":false,"strokeMiterLimit":4,"scaleX":1,"scaleY":1,"angle":0,"flipX":false,"flipY":false,"opacity":1,"shadow":null,"visible":true,"backgroundColor":"","fillRule":"nonzero","paintFirst":"fill","globalCompositeOperation":"source-over","skewX":0,"skewY":0,"text":"65","fontSize":36,"fontWeight":"normal","fontFamily":"Arial Black","fontStyle":"normal","lineHeight":1.16,"underline":false,"overline":false,"linethrough":false,"textAlign":"left","textBackgroundColor":"","charSpacing":0,"path":null,"direction":"ltr","styles":{}}]},{"type":"group","version":"4.5.0","originX":"left","originY":"top","left":214,"top":386,"width":48,"height":48,"fill":"rgb(0,0,0)","stroke":null,"strokeWidth":0,"strokeDashArray":null,"strokeLineCap":"butt","strokeDashOffset":0,"strokeLineJoin":"miter","strokeUniform":false,"strokeMiterLimit":4,"scaleX":1,"scaleY":1,"angle":0,"flipX":false,"flipY":false,"opacity":1,"shadow":null,"visible":true,"backgroundColor":"","fillRule":"nonzero","paintFirst":"fill","globalCompositeOperation":"source-over","skewX":0,"skewY":0,"objects":[{"type":"image","version":"4.5.0","originX":"left","originY":"top","left":-24,"top":-24,"width":48,"height":48,"fill":"rgb(0,0,0)","stroke":null,"strokeWidth":0,"strokeDashArray":null,"strokeLineCap":"butt","strokeDashOffset":0,"strokeLineJoin":"miter","strokeUniform":false,"strokeMiterLimit":4,"scaleX":1,"scaleY":1,"angle":0,"flipX":false,"flipY":false,"opacity":1,"shadow":null,"visible":true,"backgroundColor":"","fillRule":"nonzero","paintFirst":"fill","globalCompositeOperation":"source-over","skewX":0,"skewY":0,"cropX":0,"cropY":0,"src":"http://127.0.0.1:8000/assets/img/icone_marker.png","crossOrigin":null,"filters":[]},{"type":"text","version":"4.5.0","originX":"left","originY":"top","left":-14,"top":-19,"width":24.01,"height":40.68,"fill":"black","stroke":null,"strokeWidth":1,"strokeDashArray":null,"strokeLineCap":"butt","strokeDashOffset":0,"strokeLineJoin":"miter","strokeUniform":false,"strokeMiterLimit":4,"scaleX":1,"scaleY":1,"angle":0,"flipX":false,"flipY":false,"opacity":1,"shadow":null,"visible":true,"backgroundColor":"","fillRule":"nonzero","paintFirst":"fill","globalCompositeOperation":"source-over","skewX":0,"skewY":0,"text":"3","fontSize":36,"fontWeight":"normal","fontFamily":"Arial Black","fontStyle":"normal","lineHeight":1.16,"underline":false,"overline":false,"linethrough":false,"textAlign":"left","textBackgroundColor":"","charSpacing":0,"path":null,"direction":"ltr","styles":{}}]}],"backgroundImage":{"type":"image","version":"4.5.0","originX":"left","originY":"top","left":0,"top":0,"width":3840,"height":2160,"fill":"rgb(0,0,0)","stroke":null,"strokeWidth":0,"strokeDashArray":null,"strokeLineCap":"butt","strokeDashOffset":0,"strokeLineJoin":"miter","strokeUniform":false,"strokeMiterLimit":4,"scaleX":0.5,"scaleY":0.43,"angle":0,"flipX":false,"flipY":false,"opacity":1,"shadow":null,"visible":true,"backgroundColor":"","fillRule":"nonzero","paintFirst":"fill","globalCompositeOperation":"source-over","skewX":0,"skewY":0,"cropX":0,"cropY":0,"src":"http://127.0.0.1:8000/uploads/imagens/mapa_dia/original/5XZn382CynGFeV21uSsZpTup3b57DF3Hsy53cJZW.png","crossOrigin":null,"filters":[]}}

This is the error presented with json_decode()

Errorexception json_decode() expects Parameter 1 to be string, array Given

How can I?

1 answer

2

json_decode, as you can see in documentation, is used to decode a JSON string. That is, unless you have a JSON string, it should not work.

Here’s an example:

$string = "{\"version\": \"4.5.0\", \"objects\": {}}";
$decode = json_decode($string);

I’m not sure what this chunk of code you quoted represents, but if you have an array and want to convert it into a JSON string, you should use json_encode (see the documentation).

An example:

$array = ['versao' => '4.5.0', 'objects' => []];
$encode = json_encode($array);

If it’s interesting, see a functional example.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.