来自Flickr的Javascript JSON响应解析错误

时间:2017-06-14 08:06:24

标签: javascript json flickr

我对如何从Flickr解析json有一个误解,因为它在json前面有一个命名函数,就像这样(我用.replace()来格式化它像

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": ""
       },

这是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": ""
       },

我想使用JSON.parse();,但我得到Uncaught SyntaxError: Unexpected token <

在这两种情况下都无法解析

我不使用ajax来发出请求,我使用像Rhino这样的javascript引擎NodeJs并且是服务器端。我使用HTTP GET这样的请求访问闪烁的公共Feed(您可以实际测试它):

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

解决方案 是将&nojsoncallback=1添加到网址,以便JSON有效

0 个答案:

没有答案