How to access json data from kohana?

631 views Asked by At

I write simple function to list data for web service request.

I try to access data in my controller like this.

public function action_ListData() {
    var_dump($this->request->post("jsondata"));
    die();
}

This is my json.

{  
   "jsondata":
{  
    "id" : "1234"
    }
}

I can't access json data. It prints empty array. how can I access the data? Please advice. Thanks in advance.

1

There are 1 answers

0
Scott Jungwirth On

request->post() is for getting form encoded data like jsondata={"id":"1234"} but your entire request body is a JSON payload, so you should use this:

<?php
$data = json_decode($this->request->body(), true);
var_dump($data);