javascript – Unexpected identifier in json_encode output-ThrowExceptions

Exception or error:
echo '<script type="text/javascript">
                $("video").easyWebPlayer({ playlist:\''.json_encode($playlist).'\'

I am using the above code in a php file it produces following output.

'playlist:'[{"id":"0","url":"\/26beb276\/26beb276_0.mp4","thumb":"\/26beb276\/26beb276_0.jpg","title":"big buck test"}]'});});

It gives me error of Unexpected identifier .
How can I avoid this error.

How to solve:

Try below code:

var playlist = '<?php echo $playlist; ?>';
var jsonplaylist = JSON.parse(playlist);
echo '<script type="text/javascript">
 $(document).ready(function(){ $("video").easyWebPlayer({ playlist:'+jsonplaylist+'});


I used playlist:”‘.str_replace(“\””,”\'”,json_encode($playlist)).'” while json_encode()

and use
var jsonobj=JSON.parse(Playlist.replace(/\’/g, “\””));
at the receiver end.


I had the same console error, the error was due to quotes


<script>window.lang_arr="<?php echo json_encode($lang_arr);?></script>


<script>window.lang_arr=<?php echo json_encode($lang_arr);?></script>

It could help someone today :_)

Leave a Reply

Your email address will not be published. Required fields are marked *