How to parse JSONP data returned from remote server

前端 未结 2 1509
野趣味
野趣味 2020-12-14 02:38

I am trying to grab some data via JSONP. Using Firebug, I am able to see the data properly being returned, but I am having a hard time thinking how I have to parse it. The d

相关标签:
2条回答
  • 2020-12-14 03:02

    You don't have to parse the data. It is already a valid JavaScript object. For instance, to print the description property for the first object inside someFunction

    function someFunction(result) {
        alert(result[0].description); // alerts "Sample Description"
    }
    
    0 讨论(0)
  • 2020-12-14 03:03

    Write a function with the correct name and the correct arguments. The JS engine will do the parsing for you.

    function someFunction(data) {
        // Now data is an Array, containing a single
        // Object with 8 properties (title, link, etc)
    }
    
    0 讨论(0)
提交回复
热议问题