0

So I'm making a hybrid mobile application using angular and I have this string that comes from a $http.jsonp request. The response that I receive I'm trying to turn in to JSON. I've checked the JSON request at https://jsonformatter.curiousconcept.com/ and it seems that the JSON is valid.

The error I receive in the Chrome web console is "Uncaught Syntax Error: Unexpected token :" and I can't for the life of me work out why this would be?

Using the response from the server below, can someone tell me what I'm doing wrong here?

{
   "rss":{
      "version":"2.0",
      "xmlns:content":"http://purl.org/rss/1.0/modules/content/",
      "xmlns:wfw":"http://wellformedweb.org/CommentAPI/",
      "xmlns:dc":"http://purl.org/dc/elements/1.1/",
      "xmlns:atom":"http://www.w3.org/2005/Atom",
      "xmlns:sy":"http://purl.org/rss/1.0/modules/syndication/",
      "xmlns:slash":"http://purl.org/rss/1.0/modules/slash/",
      "channel":{
         "title":"WEBSITE TITLE",
         "link":[
            {
               "href":"https://www.WEBURL.com/feed/",
               "rel":"self",
               "type":"application/rss+xml"
            },
            "https://www.WEBURL.com"
         ],
         "description":"WEB DESCRIPTION",
         "lastBuildDate":"Fri, 25 Sep 2015 16:33:52 +0000",
         "language":"en-US",
         "updatePeriod":"hourly",
         "updateFrequency":"1",
         "generator":"http://wordpress.org/?v=4.3",
         "item":[
            {
               "title":"TITLE",
               "link":"https://www.WEBURL.com/2015/09/25/POST",
               "comments":[
                  "https://www.WEBURL.com/2015/09/25/POST/#comments",
                  "0"
               ],
               "pubDate":"Fri, 25 Sep 2015 16:27:19 +0000",
               "creator":"AUTHOR",
               "category":"CATEGORY",
               "guid":"https://www.WEBURL.com/?p=12345",
               "description":"<p>POST DESCRIPTION</p>\n",
               "encoded":"<p class=\"article-content__figure article-content--image\">POST CONTENT</p>\n",
               "commentRss":"https://www.WEBURL.com/2015/09/25/POST/feed/"
            }
         ]
      }
   }
}

The Javascript goes as:

$http.jsonp("http://jsonburner.herokuapp.com/source?feed=https://www.WEBURL.com/feed/")
            .success(function(data) {
            $scope.debug = data.rss.version
            //$scope.debug = data.rss.version

        })
        .error(function(data) {
            $scope.debug = data
            //$scope.debug = data.rss.version

        });

Thanks

Alex

2
  • I tried your feed url in the browser, it gives an error. I think thats the reason for the json not being parsed right. Commented Sep 26, 2015 at 10:08
  • Your code isn't valid in any possible format. You have something that looks like it's copied from an Angular code, then a url that's mixed with more Angular code. Commented Sep 26, 2015 at 10:37

2 Answers 2

1

I think you are confusing JSON and JSONP (see here for the difference between them).

You probably just want to use $http.get (or what ever verb the server behind the URL expects). See $http docs for details.

Sign up to request clarification or add additional context in comments.

Comments

0

You're probably looking to do this:

$http.get('http://jsonburner.herokuapp.com/source?feed=https://www.WEBURL.com/feed/')
.success(function(result) {
  var data = JSON.parse(result);
  console.log('this is what you\'re looking for: ', data);
  
}).error(function(result) {
  var data = JSON.parse(result);
});

Here you have JSONP explained: Can anyone explain what JSONP is, in layman terms?

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.