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 = [{"SubCategoryID":1,"FirstName":
"First Name","LastName":"Last Name"},
{"SubCategoryID":2,"FirstName":"First Name2",
"LastName":"Last Name2"}];
Question
Why it gives " in the json data ?
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire