0

I am building an API in PHP and when a user uses the api to POST or PUT, they will pass some data through in JSON format. When the request arrives at the script intended, what php function do I use to get access to the data sent?

Thanks!

sark9012
  • 5,485
  • 18
  • 61
  • 99

1 Answers1

0

there is json_decode function that takes string input converts to json array or object... here you can read documentation.

tanaydin
  • 5,171
  • 28
  • 45
  • How do I get access to the actual json itself though? – sark9012 Apr 14 '13 at 22:41
  • $json = json_decode($_POST['json_string'); print_r($json); – tanaydin Apr 14 '13 at 22:42
  • @tanaydin — That would only work if, after the data was JSON encoded, it was also `application/x-www-form-urlencoded` encoded or `multipart/form-data` encoded. That's sometimes done for POST requests, but is really uncommon for PUT requests. – Quentin Apr 14 '13 at 22:45