Jens Habegger
Jens Habegger

Reputation: 5446

Enumerating through Yahoo Pipes generated JSON with jQuery fails

I'm trying to lessen manual update work by using Yahoo Pipes and jQuery to update a table with upcoming events from a different domain. I have created this Pipe to gather the data, and it seems to work.

Now I am reading the JSON file with the following jQuery Script taken from this tutorial:

$.ajax({
 type: "GET",
 url: "http://pipes.yahoo.com/pipes/pipe.run?_id=57aa32bf3481c8dca0c07afcf9b9dc29&_render=json",
 async: false,
 beforeSend: function(x) {
  if(x && x.overrideMimeType) {
   x.overrideMimeType("application/j-son;charset=UTF-8");
  }
 },
  dataType: "json",
  success: function(data){
  $('body').append(data.query.results.a.content);
 }
});

The jQuery append failes, I guess because 'data.query.results.a.content' does not relate well to the JSON structure created by the pipe.

I've tried altering both the pipe and the append in several ways and am just short of giving up, I'd be very grateful for your Input.

Upvotes: 0

Views: 427

Answers (1)

Amitd
Amitd

Reputation: 4849

Think you are parsing the json result incorrectly.

On viewing the json object here http://jsonviewer.stack.hu/

You will observe content node for each item is at value.items[0].a.content

i.e. try something like this :

$('body').append(data.value.items[0].a.content);

You will need to iterate the items array like this

$.each(data.value.items, function(index,element) {
    $('body').append(element.a.content);
});

Try it on fiddle : http://jsfiddle.net/EFvJf/

Upvotes: 1

Related Questions