개발! 딱 깔끔하고 센스있게!

PHP 디 코딩 JSON POST [종료] 본문

개발 스크랩 메모/PHP

PHP 디 코딩 JSON POST [종료]

렉사이 2020. 11. 30. 02:41

제 이 슨 방식 으로 POST 데 이 터 를 받 아 보 려 고 합 니 다.

나 는 그것 을 구 부 렸 다.

curl -v --header 'content-type:application/json' -X POST --data '{"content":"test content","friends":[\"38383\",\"38282\",\"38389\"],"newFriends":0,"expires":"5-20-2013","region":"35-28"}' http://testserver.com/wg/create.php?action=post 

PHP 에 있어 서 제 코드 는:

$data = json_decode(file_get_contents('php://input')); $content = $data->{'content'}; $friends = $data->{'friends'}; // JSON array of FB IDs $newFriends = $data->{'newFriends'}; $expires = $data->{'expires'}; $region = $data->{'region'}; 

하지만 내 가 데 이 터 를 인쇄 한다 고 해서 되 돌아 오 는 것 은 아무것도 없 을 것 이다.

이것 은 표 가 없 는 게시 물 을 처리 하 는 올 바른 방법 입 니까?

대답 하 다.

제 이 슨 에 게 제출 한 데이터 가 효과 적 이지 않 습 니 다.

당신 이 "당신 의 껍데기 안에서 그것 을 처리 할 수 없다" 고 쓰 면 의심 할 것 이다.

curl -v --header 'content-type:application/json' -X POST --data '{"content":"test content","friends": ["38383","38282","38389"],"newFriends":0,"expires":"5-20-2013","region":"35-28"}' 

예 상 했 던 대로 일 하 다.

 

출력:

array(5) { ["content"]=> string(12) "test content" ["friends"]=> array(3) { [0]=> string(5) "38383" [1]=> string(5) "38282" [2]=> string(5) "38389" } ["newFriends"]=> int(0) ["expires"]=> string(9) "5-20-2013" ["region"]=> string(5) "35-28" } 
Comments