Как строка json автоматически преобразуется в объект javascript при использовании директивы @json()?Php

Кемеровские программисты php общаются здесь
Гость
Как строка json автоматически преобразуется в объект javascript при использовании директивы @json()?

Сообщение Гость »


laravel-10

Код: Выделить всё

@php
$student = ["name" => "John Doe", "age" => 20, "grade" => "A"];
@endphp

var data3 = @json($student);
console.log(data3);

If the data passed from PHP to JavaScript using @json() is passed as a JSON string then
here in this code why when we log the data3 to the console i.e. console.log(data3) then this is the output
{name: 'John Doe', age: 20, grade: 'A'}
if the data passed from PHP to JavaScript using @json() is passed as a JSON string then shouldnot this be the output
'{"name": 'John Doe', "age": 20, "grade": 'A'}'
because this is the JSON string.
It may sound like a stupid question


Источник: https://stackoverflow.com/questions/781 ... while-usin

Вернуться в «Php»