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

Why always get month=0 in as.period (lubridate package) in R

r lubridate

Using the as.period I like to know the exact difference in year, month and date. However, I always get month value equal to zero and it transforms the month into date as following:

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.