curl json 질문좀 드릴게요

curl json 질문좀 드릴게요

QA

curl json 질문좀 드릴게요

본문

curl 로 데이터를 받아오니

{"410873":{"charge":"80.00","start_count":"116","status":"Completed","remains":"0","currency":"KRW"},"410874":{"charge":"80.00","start_count":"241","status":"Completed","remains":"0","currency":"KRW"},"410903":{"charge":"0.00","start_count":null,"status":"Canceled","remains":"100","currency":"KRW"}}

 

데이터들이 이렇게 표시가 되는데 

각각 함수에 담아서 echo로 표시하고싶습니다.

허나 방법을 잘 모르겠습니다.

$response = curl_exec($curl);

$tmp=json_decode($response);

이렇게 echo 찍어보니 Array 라고만 나오고

echo $response['charge']; echo $tmp['charge']  이렇게 찍어봐도 아무것도 나오지 않는데 도와주실 분 계신가요?

이 질문에 댓글 쓰기 :

답변 1

각각 객체들 charge 출력방법입니다.


$response = curl_exec($curl);
$tmp=json_decode($response,true);
foreach($tmp as $key => $val){
    echo $tmp[$key]['charge']."<BR>";
}

var_dump 시
object(stdClass)#10 (3) { ["410873"]=> object(stdClass)#6 (5) { ["charge"]=> string(5) "80.00" ["start_count"]=> string(3) "116" ["status"]=> string(9) "Completed" ["remains"]=> string(1) "0" ["currency"]=> string(3) "KRW" } ["410874"]=> object(stdClass)#11 (5) { ["charge"]=> string(5) "80.00" ["start_count"]=> string(3) "241" ["status"]=> string(9) "Completed" ["remains"]=> string(1) "0" ["currency"]=> string(3) "KRW" } ["410903"]=> object(stdClass)#12 (5) { ["charge"]=> string(4) "0.00" ["start_count"]=> NULL ["status"]=> string(8) "Canceled" ["remains"]=> string(3) "100" ["currency"]=> string(3) "KRW" } } object(stdClass)#10 (3) { ["410873"]=> object(stdClass)#6 (5) { ["charge"]=> string(5) "80.00" ["start_count"]=> string(3) "116" ["status"]=> string(9) "Completed" ["remains"]=> string(1) "0" ["currency"]=> string(3) "KRW" } ["410874"]=> object(stdClass)#11 (5) { ["charge"]=> string(5) "80.00" ["start_count"]=> string(3) "241" ["status"]=> string(9) "Completed" ["remains"]=> string(1) "0" ["currency"]=> string(3) "KRW" } ["410903"]=> object(stdClass)#12 (5) { ["charge"]=> string(4) "0.00" ["start_count"]=> NULL ["status"]=> string(8) "Canceled" ["remains"]=> string(3) "100" ["currency"]=> string(3) "KRW" } } object(stdClass)#10 (3) { ["410873"]=> object(stdClass)#6 (5) { ["charge"]=> string(5) "80.00" ["start_count"]=> string(3) "116" ["status"]=> string(9) "Completed" ["remains"]=> string(1) "0" ["currency"]=> string(3) "KRW" } ["410874"]=> object(stdClass)#11 (5) { ["charge"]=> string(5) "80.00" ["start_count"]=> string(3) "241" ["status"]=> string(9) "Completed" ["remains"]=> string(1) "0" ["currency"]=> string(3) "KRW" } ["410903"]=> object(stdClass)#12 (5) { ["charge"]=> string(4) "0.00" ["start_count"]=> NULL ["status"]=> string(8) "Canceled" ["remains"]=> string(3) "100" ["currency"]=> string(3) "KRW" } }
이렇게 출력이 되고 있구요

답변을 작성하시기 전에 로그인 해주세요.
전체 69
QA 내용 검색

회원로그인

(주)에스아이알소프트 / 대표:홍석명 / (06211) 서울특별시 강남구 역삼동 707-34 한신인터밸리24 서관 1404호 / E-Mail: admin@sir.kr
사업자등록번호: 217-81-36347 / 통신판매업신고번호:2014-서울강남-02098호 / 개인정보보호책임자:김민섭(minsup@sir.kr)
© SIRSOFT