curl json 질문좀 드릴게요

curl json 질문좀 드릴게요

QA

curl json 질문좀 드릴게요

답변 1

본문

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" } }
이렇게 출력이 되고 있구요

답변을 작성하시기 전에 로그인 해주세요.
QA 내용 검색
질문등록
filter #curl ×
전체 96
© SIRSOFT
현재 페이지 제일 처음으로