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 = {{ json_encode($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 ?
user5694966
user5694966
asked Dec 20, 2015 at 9:26
user5694966user5694966
-
It is not completely clear what the problem is. In JSON both key in pair and string value are quotedRevolver_Ocelot– Revolver_Ocelot2015年12月20日 09:33:55 +00:00Commented Dec 20, 2015 at 9:33
1 Answer 1
The JSON string uses quotes to show where a value starts and ends in basic terms.
Give
var subCategoriesList = {!! $SubCategoryList !!};
a go. This will echo out an unescaped string for json.
answered Dec 20, 2015 at 9:34
Comments
lang-php