phpdev phpdev - 23 days ago 6
JSON Question

How to get specific element of decoded Json in yii 1?

I have following code:

public function actionsdf($id){
$dsf=UserLog::model()->findByPk($id);
$decode=$dsf->text;
var_dump($decode=$dsf->text);
$res=CJSON::decode($decode);
var_dump($res);

}


The result of
var_dump($decode=$dsf->text);
is

string(103) "{"text":"LOG_EVENT_MEMBERSHIP_FORM_SENT {time}{form_id}","params":{"{time}":"11:38","{form_id}":"402"}}"


and the result of decoded json(
var_dump($res);)
is

array(2) { ["text"]=> string(46) "LOG_EVENT_MEMBERSHIP_FORM_SENT {time}{form_id}" ["params"]=> array(2) { ["{time}"]=> string(5) "11:38" ["{form_id}"]=> string(3) "402" } }


I need to retrieve only
402
itself from form_d(where form_id=402). How can I do it?

Answer

Should be ["params"]["{form_id}"]

    $res=CJSON::decode($decode);
    var_dump($res);

    var_dump( $res["params"]["{form_id}"] );
Comments