javascript - Adding a new associative element to a JSON object -
i have problem add elements json array.
the structure want that:
[{"method":"edit","type":"1", "template":"3", "meta":{"title":"tools", "descirption":"tools"}}]
the problem add these parameters dynamically.
so lets have start:
[{"method":"edit","type":"1", "template":"3"}]
how can add whole "meta" array , please not push(), because have structure when print it.
when use
$json = json_decode($json, true);
i want have:
array( method' => edit, 'type' => 1, 'template' => 3, 'meta' => array('title' => '') );
thanks in advice !
so i'm going assume have json start with. let's decode php (as noted correctly)
$json = json_decode($json, true);
so should have $json['method']
, etc. let's define $meta
$meta = array('title' => '');
and add $json
$json['meta'] = $meta; echo json_encode($json);
Comments
Post a Comment