1

I need to convert a RSS feed from another domain and turn it into json. In order to circumvent cross-domain warnings, I'm parsing the RSS feed server side using this PHP proxy script.

  • but somehow the response is in one long string.

I would like to use ajax like this:

var url = "http://www.mywebsite.net/simple-proxy.php?url=http://feeds.bbci.co.uk/news/rss.xml?edition=int&callback=feed";
    $.ajax({
        dataType: "jsonp",
        url: url,
        success: function(data) {
            console.log(data);
        }
    });

- but somehow the response is in one long string. How do I get the response turned into a json array with nodes, and so on?

2 Answers 2

2

Get the string and then convert it into JSON: I see you are using jquery so...

$.parseJSON(jsonString);
Sign up to request clarification or add additional context in comments.

4 Comments

Doing this throws an error: Uncaught SyntaxError: Unexpected token o in JSON at position 1 Could it be related to quotes or something?
Check the data type of the data variable, if it is already JSON it will give you such an error. Otherwise, make sure you have set the correct headers. If the header is already application/JSON you dont need to parse.
Ok, thanks. How do I do that in the PHP Proxy above?
To set the PHP headers, use: header('application/json'); But i reccomend checking the type in JS: console.log(typeof data);
-1

I found a solution using SQL instead.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.