json_encode wont remove backslashes

I'm trying to generate JSON in php. My problem is that some backslashes stays in the json string, even though i use json_encode:

header('Cache-Control: no-cache, must-revalidate');
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Content-type: application/json');

$jsonurl = 'http://api.flickr.com/services/rest/?method=flickr.photos.getSizes&api_key=e6c27be80b3b54c55376a5f59009a8db&photo_id=7962163506&format=json&nojsoncallback=1';
$json = file_get_contents($jsonurl);

echo json_encode($json);

Result:

"{\"sizes\":{\"canblog\":0, \"canprint\":0, \"candownload\":1, \"size\":[{\"label\":\"Square\", \"width\":75, \"height\":75, \"source\":\"http:\\\/\\\/farm9.staticflickr.com\\\/8318\\\/7962163506_139d6bf0a0_s.jpg\", \"url\":\"http:\\\/\\\/www.flickr.com\\\/photos\\\/87015633@N08\\\/7962163506\\\/sizes\\\/sq\\\/\", \"media\":\"photo\"}, {\"label\":\"Large Square\", \"width\":\"150\", \"height\":\"150\", \"source\":\"http:\\\/\\\/farm9.staticflickr.com\\\/8318\\\/7962163506_139d6bf0a0_q.jpg\", \"url\":\"http:\\\/\\\/www.flickr.com\\\/photos\\\/87015633@N08\\\/7962163506\\\/sizes\\\/q\\\/\", \"media\":\"photo\"}, {\"label\":\"Thumbnail\", \"width\":\"100\", \"height\":\"66\", \"source\":\"http:\\\/\\\/farm9.staticflickr.com\\\/8318\\\/7962163506_139d6bf0a0_t.jpg\", \"url\":\"http:\\\/\\\/www.flickr.com\\\/photos\\\/87015633@N08\\\/7962163506\\\/sizes\\\/t\\\/\", \"media\":\"photo\"}, {\"label\":\"Small\", \"width\":\"240\", \"height\":\"159\", \"source\":\"http:\\\/\\\/farm9.staticflickr.com\\\/8318\\\/7962163506_139d6bf0a0_m.jpg\", \"url\":\"http:\\\/\\\/www.flickr.com\\\/photos\\\/87015633@N08\\\/7962163506\\\/sizes\\\/s\\\/\", \"media\":\"photo\"}, {\"label\":\"Small 320\", \"width\":\"320\", \"height\":212, \"source\":\"http:\\\/\\\/farm9.staticflickr.com\\\/8318\\\/7962163506_139d6bf0a0_n.jpg\", \"url\":\"http:\\\/\\\/www.flickr.com\\\/photos\\\/87015633@N08\\\/7962163506\\\/sizes\\\/n\\\/\", \"media\":\"photo\"}, {\"label\":\"Medium\", \"width\":\"500\", \"height\":\"331\", \"source\":\"http:\\\/\\\/farm9.staticflickr.com\\\/8318\\\/7962163506_139d6bf0a0.jpg\", \"url\":\"http:\\\/\\\/www.flickr.com\\\/photos\\\/87015633@N08\\\/7962163506\\\/sizes\\\/m\\\/\", \"media\":\"photo\"}, {\"label\":\"Medium 640\", \"width\":\"640\", \"height\":\"424\", \"source\":\"http:\\\/\\\/farm9.staticflickr.com\\\/8318\\\/7962163506_139d6bf0a0_z.jpg\", \"url\":\"http:\\\/\\\/www.flickr.com\\\/photos\\\/87015633@N08\\\/7962163506\\\/sizes\\\/z\\\/\", \"media\":\"photo\"}, {\"label\":\"Medium 800\", \"width\":\"800\", \"height\":530, \"source\":\"http:\\\/\\\/farm9.staticflickr.com\\\/8318\\\/7962163506_139d6bf0a0_c.jpg\", \"url\":\"http:\\\/\\\/www.flickr.com\\\/photos\\\/87015633@N08\\\/7962163506\\\/sizes\\\/c\\\/\", \"media\":\"photo\"}, {\"label\":\"Large\", \"width\":\"1024\", \"height\":\"678\", \"source\":\"http:\\\/\\\/farm9.staticflickr.com\\\/8318\\\/7962163506_139d6bf0a0_b.jpg\", \"url\":\"http:\\\/\\\/www.flickr.com\\\/photos\\\/87015633@N08\\\/7962163506\\\/sizes\\\/l\\\/\", \"media\":\"photo\"}]}, \"stat\":\"ok\"}"

Expected result:

{"sizes":{"canblog":0, "canprint":0, "candownload":1, "size":[{"label":"Square", "width":75, "height":75, "source":"http:\/\/farm9.staticflickr.com\/8306\/7962671096_61367d4804_s.jpg", "url":"http:\/\/www.flickr.com\/photos\/87015633@N08\/7962671096\/sizes\/sq\/", "media":"photo"}, {"label":"Large Square", "width":"150", "height":"150", "source":"http:\/\/farm9.staticflickr.com\/8306\/7962671096_61367d4804_q.jpg", "url":"http:\/\/www.flickr.com\/photos\/87015633@N08\/7962671096\/sizes\/q\/", "media":"photo"}, {"label":"Thumbnail", "width":"100", "height":"66", "source":"http:\/\/farm9.staticflickr.com\/8306\/7962671096_61367d4804_t.jpg", "url":"http:\/\/www.flickr.com\/photos\/87015633@N08\/7962671096\/sizes\/t\/", "media":"photo"}, {"label":"Small", "width":"240", "height":"159", "source":"http:\/\/farm9.staticflickr.com\/8306\/7962671096_61367d4804_m.jpg", "url":"http:\/\/www.flickr.com\/photos\/87015633@N08\/7962671096\/sizes\/s\/", "media":"photo"}, {"label":"Small 320", "width":"320", "height":212, "source":"http:\/\/farm9.staticflickr.com\/8306\/7962671096_61367d4804_n.jpg", "url":"http:\/\/www.flickr.com\/photos\/87015633@N08\/7962671096\/sizes\/n\/", "media":"photo"}, {"label":"Medium", "width":"500", "height":"331", "source":"http:\/\/farm9.staticflickr.com\/8306\/7962671096_61367d4804.jpg", "url":"http:\/\/www.flickr.com\/photos\/87015633@N08\/7962671096\/sizes\/m\/", "media":"photo"}, {"label":"Medium 640", "width":"640", "height":"424", "source":"http:\/\/farm9.staticflickr.com\/8306\/7962671096_61367d4804_z.jpg", "url":"http:\/\/www.flickr.com\/photos\/87015633@N08\/7962671096\/sizes\/z\/", "media":"photo"}, {"label":"Medium 800", "width":"800", "height":530, "source":"http:\/\/farm9.staticflickr.com\/8306\/7962671096_61367d4804_c.jpg", "url":"http:\/\/www.flickr.com\/photos\/87015633@N08\/7962671096\/sizes\/c\/", "media":"photo"}, {"label":"Large", "width":"1024", "height":"678", "source":"http:\/\/farm9.staticflickr.com\/8306\/7962671096_61367d4804_b.jpg", "url":"http:\/\/www.flickr.com\/photos\/87015633@N08\/7962671096\/sizes\/l\/", "media":"photo"}]}, "stat":"ok"}

What do i need to change to get a correct JSON string?

Answers


It looks like your call json_encode on a JSON string, just output it.

header('Cache-Control: no-cache, must-revalidate');
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Content-type: application/json');

$jsonurl = 'http://api.flickr.com/services/rest/?method=flickr.photos.getSizes&api_key=e6c27be80b3b54c55376a5f59009a8db&photo_id=7962163506&format=json&nojsoncallback=1';
echo file_get_contents($jsonurl);

Need Your Help

ASP.Net Browser Definition Files to solve IE10 javascript postback issues

asp.net internet-explorer-10

I have a website built using Framework 2.0. In IE10 the javascript postbacks for link buttons don't work. To try to solve this I have followed Scott Hanselman's instructions

Decent tools for decoding images

image encoding image-manipulation gimp

I have a HEX dump which I'm told is a PNG file and hence want to convert it into the PNG so I can view/manipulate appropriately.