2012-06-11 4 views
0

나는 PHP를 사용하고 있습니다. 내 출력물을 작동시키는 데 문제가 있습니다. 내 json 파일이 완벽하지 않기 때문에 나는 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://rads.stackoverflow.com/amzn/click/B004SBW1LS", 
    "id": "ctl00_ctl00_cphMain_cphMiddleColumn_grdSongs_ctl03_hypAmazon", 
    "target": "_blank", 
    "content": "Amazon" 
    }, 
    "content": "| " 
    } 
    } 
] 
} 

,이 YQL을 가진 웹 사이트에서 내 html로 스크랩에서 내 항목 중 하나입니다. 나는 "우리가 진짜 였으면 어떻게 될 것인가?" 하지만 json 개체 제목은 "p"이고 "어떻게하면 우리가 진짜 였는지"를 추출하는 방법을 모른다. 필자 시도

,

$albumname = $item->p 

,하지만 당신의 목록에 다수의 "P"가 있습니다 볼 수 있습니다. 어떤 도움이라도 좋을 것입니다. 감사.

답변

1

같은 괴물에 대해 오는 메신저 단순히 이렇게 제일 먼저 :

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

다음 쉬운 것을 찾을 수 있습니다 :

echo $estr["td"][4]["p"];