0

i have a missunderstanding on how to parse the json from Flickr because it has a named function in front of json like this ( I used .replace() to format it like this )

jsonFlickrFeed({
        "title": "Uploads from everyone",
        "link": "https://www.flickr.com/photos/",
        "description": "",
        "modified": "2017-06-14T08:08:45Z",
        "generator": "https://www.flickr.com",
        "items": [
       {
            "title": "PICT5162",
            "link": "https://www.flickr.com/photos/57727182@N08/34455881614/",
            "media": {"m":"https://farm5.staticflickr.com/4252/34455881614_c488502d97_m.jpg"},
            "date_taken": "2011-01-01T08:20:44-08:00",
            "description": " <p><a href="https://www.flickr.com/people/57727182@N08/">bobbyblack51</a> posted a photo:</p> <p><a href="https://www.flickr.com/photos/57727182@N08/34455881614/" title="PICT5162"><img src="https://farm5.staticflickr.com/4252/34455881614_c488502d97_m.jpg" width="240" height="160" alt="PICT5162" /></a></p> ",
            "published": "2017-06-14T08:08:45Z",
            "author": "nobody@flickr.com ("bobbyblack51")",
            "author_id": "57727182@N08",
            "tags": ""
       },
       {
            "title": "Chup len mong",
            "link": "https://www.flickr.com/photos/151619623@N04/34455882074/",
            "media": {"m":"https://farm5.staticflickr.com/4250/34455882074_4cc00653c2_m.jpg"},
            "date_taken": "2017-06-12T09:10:58-08:00",
            "description": " <p><a href="https://www.flickr.com/people/151619623@N04/">huynhtri1</a> posted a photo:</p> <p><a href="https://www.flickr.com/photos/151619623@N04/34455882074/" title="Chup len mong"><img src="https://farm5.staticflickr.com/4250/34455882074_4cc00653c2_m.jpg" width="180" height="240" alt="Chup len mong" /></a></p> ",
            "published": "2017-06-14T08:08:46Z",
            "author": "nobody@flickr.com ("huynhtri1")",
            "author_id": "151619623@N04",
            "tags": ""
       },

and this is the actual true response from Flickr :

jsonFlickrFeed({
        "title": "Uploads from everyone",
        "link": "https:\/\/www.flickr.com\/photos\/",
        "description": "",
        "modified": "2017-06-14T08:13:53Z",
        "generator": "https:\/\/www.flickr.com",
        "items": [
       {
            "title": " ",
            "link": "https:\/\/www.flickr.com\/photos\/155707338@N06\/34455957324\/",
            "media": {"m":"https:\/\/farm5.staticflickr.com\/4266\/34455957324_c1657846cb_m.jpg"},
            "date_taken": "2017-05-31T13:57:23-08:00",
            "description": " <p><a href=\"https:\/\/www.flickr.com\/people\/155707338@N06\/\">gulicolam<\/a> posted a photo:<\/p> <p><a href=\"https:\/\/www.flickr.com\/photos\/155707338@N06\/34455957324\/\" title=\" \"><img src=\"https:\/\/farm5.staticflickr.com\/4266\/34455957324_c1657846cb_m.jpg\" width=\"240\" height=\"180\" alt=\" \" \/><\/a><\/p> ",
            "published": "2017-06-14T08:13:53Z",
            "author": "nobody@flickr.com (\"gulicolam\")",
            "author_id": "155707338@N06",
            "tags": ""
       },
       {
            "title": "My specs",
            "link": "https:\/\/www.flickr.com\/photos\/133444761@N05\/34489902583\/",
            "media": {"m":"https:\/\/farm5.staticflickr.com\/4266\/34489902583_b84ce9132a_m.jpg"},
            "date_taken": "2017-06-14T09:12:50-08:00",
            "description": " <p><a href=\"https:\/\/www.flickr.com\/people\/133444761@N05\/\">sabre aviation<\/a> posted a photo:<\/p> <p><a href=\"https:\/\/www.flickr.com\/photos\/133444761@N05\/34489902583\/\" title=\"My specs\"><img src=\"https:\/\/farm5.staticflickr.com\/4266\/34489902583_b84ce9132a_m.jpg\" width=\"240\" height=\"180\" alt=\"My specs\" \/><\/a><\/p> <p>cof<\/p>",
            "published": "2017-06-14T08:13:47Z",
            "author": "nobody@flickr.com (\"sabre aviation\")",
            "author_id": "133444761@N05",
            "tags": ""
       },

i want to use JSON.parse(); but i get Uncaught SyntaxError: Unexpected token <

In both cases it cannot be parsed

I dont use ajax to make request , i use a javascript engine Rhino like NodeJs and is serverside . I access the flicker public feed with a HTTP GET request like this (you can actually test it) :

https://api.flickr.com/services/feeds/photos_public.gne?format=json&lang=en-us&nojsoncallback=1

THE SOLUTION was to add &nojsoncallback=1 to the url so the JSON be valid

123onetwothree
  • 636
  • 1
  • 8
  • 17

0 Answers0