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

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -