2010-02-10 5 views
2

이 내가 공급 파인더 URL (JSON 인코딩)에서 문자열로 무엇을 얻을 : PHP에서이 JSON 문자열을 디코딩하는 방법은 무엇입니까?

{"updated":1265787927,"id":"http://www.google.com/reader/api/0/feed-finder?q\u003dhttp://itcapsule.blogspot.com/\u0026output\u003djson","title":"Feed results for \"http://itcapsule.blogspot.com/\"","self":[{"href":"http://www.google.com/reader/api/0/feed-finder?q\u003dhttp://itcapsule.blogspot.com/\u0026output\u003djson"}],"feed":[{"href":"http://itcapsule.blogspot.com/feeds/posts/default"}]} 

어떻게 내가 json_decode를 사용하여 디코딩 할 수있다() 함수와 마지막 배열 요소 ("공급")를 얻을 ? 나는 json_decode()는 이미 두 번째 매개 변수로 true로 전화 배열을 반환

+1

내가 오해하고 있지만 단지 $ ar [ 'feed']를 원한다면 사과드립니다. – jasonbar

+0

PHP에서 타입 캐스팅이 필요 없습니다. –

+0

@Jasonbar, 예. 맞습니다. 피드 값만 필요합니다. – Orion

답변

2
$array = json_decode($json, true); 
$feed = $array['feed']; 

주 .. 다음 코드 만

$json = file_get_contents("http://www.google.com/reader/api/0/feed-finder?q=http://itcapsule.blogspot.com/&output=json"); 
$ar = (array)(json_decode($json,true)); 
print_r $ar; 

이 도와주세요 행운과 그것을 시도.

이 업데이트 : JSON

"feed":[{"href":"http://itcapsule.blogspot.com/feeds/posts/default"}] 

에서 feed의 값으로

객체의 배열입니다, $array['feed']의 내용은 다음과 같습니다

Array 
(
    [0] => Array 
     (
      [href] => http://itcapsule.blogspot.com/feeds/posts/default 
     ) 
) 

이 URL을 얻으려면 $array['feed'][0]['href'] 또는 $feed[0]['href']으로 배열에 액세스해야합니다.

그러나 이것은 배열의 기본 처리입니다. 어쩌면 Arrays documentation이 도움이됩니다.

+0

@Felix, 이제 결과가 "배열"로 표시됩니다. ( – Orion

+0

@Raveesh : 업데이트 된 답변보기 –

+0

감사합니다. – Orion

관련 문제