如何验证codeigniter中的json对象?

时间:2013-01-15 06:02:50

标签: json codeigniter

 var trans = { 
     amount: $('#container input:first-child').val(),
     note: $('#container input:last-child').val()
    };  // javascript

 trans =  {
     "amount":"",
     "note":"",
 }  // json 

$trans = $this->input->post('trans');
$t = json_decode($trans);

$amount = $t->amount;
$note = $t->note;

$this->form_validation->set_rules('amount', 'Amount', 'required');

错误是

  Call to a member function set_rules() on a non-object in......

如何验证json对象?

1 个答案:

答案 0 :(得分:0)

尝试在构造函数中加载form_validation

function __construct() {
    parent::__construct();
    $this->load->library('form_validation');
}