dimanche 20 décembre 2015

Error in Json Data : Laravel 5.1

What is it about ?

I am adding the elements in an array and finally trying to convert that array into Json. Below is the code.

$SubCategoryList = array();

array_push($SubCategoryList, 
            array(
                'SubCategoryID' =>  1,
                'FirstName'   =>  'First Name',
                'LastName'    =>  'Last Name',
            ));
array_push($SubCategoryList, 
            array(
                'SubCategoryID' =>  2,
                'FirstName'   =>  'First Name2',
                'LastName'    =>  'Last Name2',
            ));

The above gives below mentioned output

Array
(
    [0] => Array
        (
            [SubCategoryID] => 1
            [FirstName] => First Name
            [LastName] => Last Name
        )

    [1] => Array
        (
            [SubCategoryID] => 2
            [FirstName] => First Name2
            [LastName] => Last Name2
        )

)

Below is the code used for converting the array into Json.

<script>
     var subCategoriesList = {{ $SubCategoryList }};
</script>

and Finally json gives below output. Which can be seen in View source

var subCategoriesList = [{&quot;SubCategoryID&quot;:1,&quot;FirstName&quot;:
&quot;First Name&quot;,&quot;LastName&quot;:&quot;Last Name&quot;},
{&quot;SubCategoryID&quot;:2,&quot;FirstName&quot;:&quot;First Name2&quot;,
&quot;LastName&quot;:&quot;Last Name2&quot;}];

Question

Why it gives " in the json data ?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire