Как строка 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
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

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