Почему json_encode добавляет обратную косую черту?Php

Кемеровские программисты php общаются здесь
Ответить
Гость
 Почему json_encode добавляет обратную косую черту?

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


Я использую

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

json_encode
for a long time, and I've not had any problems so far.
Now I'm working with a upload script and I try to return some JSON data after file upload.

I have the following code:

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

print_r($result); //  54
[feedback] => Array
(
[message] => File uploaded
[success] => 1
)

)

// Echo result
{"logo_url":"http:\/\/mysite.com\/uploads\/gallery\/7f\/3b\/f65ab8165d_logo.jpeg","img_id":"54","feedback":{"message":"File uploaded","success":true}}
Can anyone tell me why

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

json_encode
adds slashes?

update

@Quentin said that something is happening between

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

json_encode
and

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

.parseJSON
and he's right.

Doing a

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

alert(data.toSource());
gives me the dollowing result:

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

({response:"{\"logo_url\":\"http:\\/\\/storelocator.com\\/wp-content\\/uploads\\/gallery\\/7f\\/3b\\/71b9520cfc91a90afbdbbfc9d2b2239b_logo.jpeg\",\"img_id\":\"62\",\"feedback\":{\"message\":\"File uploaded\",\"success\":true}}", status:200})
And this is not valid JSON. It also adds the

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

status:200
and I have no idea where this comes from.

Could it be that the

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

Plupload bind
does something to my returned data?

This is my js script:

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

  uploader.bind('FileUploaded', function(up, file, data) {
alert(data.toSource());
$('#' + file.id + " b").html("100%");
});


Источник: https://stackoverflow.com/questions/103 ... ackslashes
Ответить

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

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

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

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

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