2011-10-29 14 views
0

と私は、しかし、私は私が望む私の文字列を構築するカントは私の人生のためにhttp://pipes.yahoo.com/pipes/pipe.run?_id=32188be96d1caf97c46a6fcfd8c00820&_render=json失敗はJSON

{ 
"count":4, 
"value":{ 
    "title":"Copy of Twitter Farm #talkdesign Pipe", 
    "description":"Pipes Output", 
    "link":"http:\/\/pipes.yahoo.com\/pipes\/pipe.info?_id=32188be96d1caf97c46a6fcfd8c00820", 
    "pubDate":"Sat, 29 Oct 2011 05:40:41 -0700", 
    "generator":"http:\/\/pipes.yahoo.com\/pipes\/", 
    "callback":"", 
    "items":[ 
    { 
     "link":"http:\/\/twitter.com\/talk_design\/statuses\/130251640623214592", 
     "description":"talk_design: Pretty cool interactive music video for Ellie Goulding's Lights! <a rel=\"nofollow\" target=\"_blank\" href=\"http:\/\/search.twitter.com\/search?q=%23webgl\" title=\"#webgl\" class=\" \">#webgl<\/a> <a rel=\"nofollow\" target=\"_blank\" href=\"http:\/\/t.co\/kkA3ON09\">http:\/\/t.co\/kkA3ON09<\/a>", 
     "pubDate":"Sat, 29 Oct 2011 11:56:25 +0000", 
     "guid":"http:\/\/twitter.com\/talk_design\/statuses\/130251640623214592", 
     "author":"[email protected] (Talk.Design)", 
     "media:content":{ 
      "height":"48", 
      "type":"image\/jpg", 
      "url":"http:\/\/a1.twimg.com\/profile_images\/1611029053\/iphone-4-icon_normal.png", 
      "width":"48" 
     }, 
     "google:image_link":"http:\/\/a1.twimg.com\/profile_images\/1611029053\/iphone-4-icon_normal.png", 
     "twitter:metadata":{ 
      "twitter:result_type":"recent" 
     }, 
     "y:published":{ 
      "hour":"11", 
      "timezone":"UTC", 
      "second":"25", 
      "month":"10", 
      "month_name":"October", 
      "minute":"56", 
      "utime":"1319889385", 
      "day":"29", 
      "day_ordinal_suffix":"th", 
      "day_of_week":"6", 
      "day_name":"Saturday", 
      "year":"2011" 
     }, 
     "y:id":{ 
      "permalink":"false", 
      "value":"http:\/\/twitter.com\/talk_design\/statuses\/130251640623214592" 
     }, 
     "y:title":"talk_design: Pretty cool interactive music video for Ellie Goulding's Lights! #webgl http:\/\/t.co\/kkA3ON09", 
     "title":"We Said: Pretty cool interactive music video for Ellie Goulding's Lights! #webgl http:\/\/t.co\/kkA3ON09" 
    }, 
    { 
     "link":"http:\/\/twitter.com\/OwenMelbz\/statuses\/129989645940428800", 
     "description":"OwenMelbz: @<em>talk_design<\/em> #<em>talk_design<\/em> test test test", 
     "pubDate":"Fri, 28 Oct 2011 18:35:21 +0000", 
     "guid":"http:\/\/twitter.com\/OwenMelbz\/statuses\/129989645940428800", 
     "author":"[email protected] (Owen Melbourne)", 
     "media:content":{ 
      "height":"48", 
      "type":"image\/jpg", 
      "url":"http:\/\/a1.twimg.com\/profile_images\/702379978\/DSC01872222_normal.jpg", 
      "width":"48" 
     }, 
     "google:image_link":"http:\/\/a1.twimg.com\/profile_images\/702379978\/DSC01872222_normal.jpg", 
     "twitter:metadata":{ 
      "twitter:result_type":"recent" 
     }, 
     "y:published":{ 
      "hour":"18", 
      "timezone":"UTC", 
      "second":"21", 
      "month":"10", 
      "month_name":"October", 
      "minute":"35", 
      "utime":"1319826921", 
      "day":"28", 
      "day_ordinal_suffix":"th", 
      "day_of_week":"5", 
      "day_name":"Friday", 
      "year":"2011" 
     }, 
     "y:id":{ 
      "permalink":"false", 
      "value":"http:\/\/twitter.com\/OwenMelbz\/statuses\/129989645940428800" 
     }, 
     "y:title":"OwenMelbz: @talk_design #talk_design test test test", 
     "title":"OwenMelbz: #talkdesign test test test" 
    }, 
    { 
     "link":"http:\/\/twitter.com\/talk_design\/statuses\/129988795574657024", 
     "description":"talk_design: Video: Jay Bradner: Open-source cancer researchFrom: TEDtalksDirector | Oct 27, 2011 | 7,265... <a rel=\"nofollow\" target=\"_blank\" href=\"http:\/\/t.co\/5hrxfCHC\">http:\/\/t.co\/5hrxfCHC<\/a>", 
     "pubDate":"Fri, 28 Oct 2011 18:31:58 +0000", 
     "guid":"http:\/\/twitter.com\/talk_design\/statuses\/129988795574657024", 
     "author":"[email protected] (Talk.Design)", 
     "media:content":{ 
      "height":"48", 
      "type":"image\/jpg", 
      "url":"http:\/\/a1.twimg.com\/profile_images\/1611029053\/iphone-4-icon_normal.png", 
      "width":"48" 
     }, 
     "google:image_link":"http:\/\/a1.twimg.com\/profile_images\/1611029053\/iphone-4-icon_normal.png", 
     "twitter:metadata":{ 
      "twitter:result_type":"recent" 
     }, 
     "y:published":{ 
      "hour":"18", 
      "timezone":"UTC", 
      "second":"58", 
      "month":"10", 
      "month_name":"October", 
      "minute":"31", 
      "utime":"1319826718", 
      "day":"28", 
      "day_ordinal_suffix":"th", 
      "day_of_week":"5", 
      "day_name":"Friday", 
      "year":"2011" 
     }, 
     "y:id":{ 
      "permalink":"false", 
      "value":"http:\/\/twitter.com\/talk_design\/statuses\/129988795574657024" 
     }, 
     "y:title":"talk_design: Video: Jay Bradner: Open-source cancer researchFrom: TEDtalksDirector | Oct 27, 2011 | 7,265... http:\/\/t.co\/5hrxfCHC", 
     "title":"We Said: Video: Jay Bradner: Open-source cancer researchFrom: TEDtalksDirector | Oct 27, 2011 | 7,265... http:\/\/t.co\/5hrxfCHC" 
    }, 
    { 
     "link":"http:\/\/twitter.com\/talk_design\/statuses\/129986263011950592", 
     "description":"talk_design: setting up website and facebook :)", 
     "pubDate":"Fri, 28 Oct 2011 18:21:54 +0000", 
     "guid":"http:\/\/twitter.com\/talk_design\/statuses\/129986263011950592", 
     "author":"[email protected] (Talk.Design)", 
     "media:content":{ 
      "height":"48", 
      "type":"image\/jpg", 
      "url":"http:\/\/a1.twimg.com\/profile_images\/1611029053\/iphone-4-icon_normal.png", 
      "width":"48" 
     }, 
     "google:image_link":"http:\/\/a1.twimg.com\/profile_images\/1611029053\/iphone-4-icon_normal.png", 
     "twitter:metadata":{ 
      "twitter:result_type":"recent" 
     }, 
     "y:published":{ 
      "hour":"18", 
      "timezone":"UTC", 
      "second":"54", 
      "month":"10", 
      "month_name":"October", 
      "minute":"21", 
      "utime":"1319826114", 
      "day":"28", 
      "day_ordinal_suffix":"th", 
      "day_of_week":"5", 
      "day_name":"Friday", 
      "year":"2011" 
     }, 
     "y:id":{ 
      "permalink":"false", 
      "value":"http:\/\/twitter.com\/talk_design\/statuses\/129986263011950592" 
     }, 
     "y:title":"talk_design: setting up website and facebook :)", 
     "title":"We Said: setting up website and facebook :)" 
    } 
    ] 
} 
} 

@パイプJSONフィードを持っています。私が使っている "理論"があります。

while i <= json[count]{ //open loop using json count data 
    tweet = json[items[i]][description]; //get the tweet 
    tweet = tweet.replace(/\/g,""); //remove slashes 
    by = json[items[i]][author]; //get author 
    by = by.split("("); //ignore full name just get short 
    by = by[1]; // shortname 
    by = by.replace(/)/g,""); //remove last) 
    avatar = json[items[i]][media:content][url]; //get avatar url 
    avatar = avatar.replace(/\/g, "") //remove slashes 
    tweet = "<img src=""+avatar+"" width=\"16\" height=\"16\" />"+author+": "+tweet; //format the tweet 
    $("#tweetarea").append(tweet); //print it to #tweetarea 
    i++ //update counter 
} //close loop 

しかし、正に私はこのjson larkを理解できません。誰でもこのjsonを解析するためのjqueryコードを書く意思があります。上記のアクションを実行しますか?

はあなたに感謝:)

+1

あなたの答えを得るのを助ける正確できちんとした形式であなたの質問を整理しようとする... – abhijit

+0

これは何か良いですか?ありがとう – Owen

答えて

1

あなたは簡単にJSONを反復して#tweetareaに特定のツイートデータを追加するjQueryのeach()メソッドを使用することができます。

$.each(json.value.items, function(i, tweet) { 
     var author = tweet.author.split('(')[1].replace(')',''); 
     var avatar = tweet['media:content'].url; 
     $('#tweetarea').append('<img src="'+avatar+'" width="16" height="16" />'+author+': '+tweet['y:title']+'<br/>'); 
}); 

あなたはjQueryの経由でJSONを読み込むことができます

Working demo

編集を参照してください。 10方法。ここにはupdated demoがあります。

+0

ああこれは華麗な感謝ですが、どのように私はvar jsonにフィードを読み込むつもりですか? – Owen

1

はJSONPの設定/ wのjQueryのAJAX APIを使用してください。

$.ajax({ 
    url: 'yahoourlhere?callback=?' 
    dataType: 'jsonp', 
}).success(function(response, status, jqxhr) { 

}).error(function(jqxhr, status, error) { 

}); 

PIPEsフィードを囲むコールバックの名前を取得できるかどうかを確認する必要があります。これは、JSONP呼び出しのJSONをラップだろうかのPHPの例です:

<?php 
    $callback = $_REQUEST['callback']; 
    echo "$callback\($json\)"; 
?> 
関連する問題