0

私はphpを使用しています。出力を機能させるのに問題があります。私は yql で html をスクレイピングしているので、json ファイルは完全ではありません。例えば、

{
 "td": [
  {
   "a": {
    "class": "audioPlayer",
    "href": "http://files.emfcdn.com/downloads/audio/hooks/3567.mp3",
    "img": {
     "border": "0",
     "class": "audioPlayer",
     "height": "22",
     "onmouseout": "this.src='/images/music/songplay-norm.jpg'",
     "onmouseover": "this.src='/images/music/songplay-over.jpg'",
     "src": "/images/music/songplay-norm.jpg",
     "width": "30"
    }
   }
  },
  {
   "p": "2."
  },
  {
   "img": {
    "alt": "Mandisa",
    "id": "ctl00_ctl00_cphMain_cphMiddleColumn_grdSongs_ctl03_imgAlbum",
    "src": "http://objects.klove.com/Common/Thumbnail.aspx?f=/art/albumart/1704.jpg&s=58&",
    "style": "border-width:0px;"
   }
  },
  {
   "a": {
    "href": "/music/artists/mandisa/songs/good-morning-(feat.-tobymac)-lyrics.aspx",
    "id": "ctl00_ctl00_cphMain_cphMiddleColumn_grdSongs_ctl03_hypTitle",
    "style": "font-weight:bold;",
    "content": "Good Morning (feat. tobyMac)"
   },
   "br": null,
   "p": {
    "a": {
     "href": "/music/artists/mandisa/",
     "id": "ctl00_ctl00_cphMain_cphMiddleColumn_grdSongs_ctl03_Hyperlink1",
     "content": "Mandisa"
    },
    "content": "by "
   }
  },
  {
   "p": "What If We Were Real"
  },
  {
   "style": "width:110px;",
   "a": {
    "href": "http://click.linksynergy.com/fs-bin/stat?id=SUbYnR25dhw&offerid=146261&type=3&subid=0&tmpid=1826&RD_PARM1=http%253A%252F%252Fitunes.apple.com%252Fus%252Falbum%252Fid425892874%253Fi%253D425892890%2526uo%253D4%2526partnerId%253D30",
    "id": "ctl00_ctl00_cphMain_cphMiddleColumn_grdSongs_ctl03_hypItunes",
    "target": "_blank",
    "content": "iTunes"
   },
   "p": {
    "a": {
     "href": "http://www.amazon.com/exec/obidos/ASIN/B004SBW1LS/klr-20/ref=nosim/",
     "id": "ctl00_ctl00_cphMain_cphMiddleColumn_grdSongs_ctl03_hypAmazon",
     "target": "_blank",
     "content": "Amazon"
    },
    "content": "| "
   }
  }
 ]
}

、これは、yql を使用した Web サイトからの html スクレイプからの私の項目の 1 つです。「What If We We We We Were Real」とエコーする変数が必要です。しかし、jsonオブジェクトのタイトルは「p」で、そこから「What If We Were Real」を抽出する方法がわかりません。

私はもう試した、

$albumname = $item->p

ですが、ご覧のとおり、リストには複数の「p」があります。どんな助けでも素晴らしいでしょう。ありがとう。

4

1 に答える 1

1

私がそのようなモンスターに直面したとき、私は最初にこれをするだけです:

$estr = json_decode($str,TRUE);
echo "<pre>";
print_r($estr);
echo "</pre>";

次に、それを見つけるのは簡単です:

echo $estr["td"][4]["p"];
于 2012-06-11T19:15:51.023 に答える