javascript - How to remove element array "[" & "]" in json? -
i possessed variable json encoded, there elements in json array "[" , "]". question is? how remove element.
this illustration of json before changing
[{ "form": { "user_id": "1", "form_id": 26, "form_name": "kirenius", "form_description": "afafasf", "form_json": [{ "id": 72043, "name": "edittext", "input_type": "text", "hint": "", "options": "" }, { "id": "409289", "name": "ini spinner", "input_type": "spinner", "hint": "ini saya ro", "options": "saya, dan dia" }], "created_at": "17-10-2014_16:49", "created_by": "adminweb", "last_updated_at": "17-10-2014_16:49" } }]
php:
$jadi_json = array(); foreach($model $row) { $json_converter = json_decode($row->json_form); $saya = array( "form"=>array( "user_id"=>$row->id_user, "form_id"=>$row->id_form, "form_name"=>$row->form_name, "form_description"=>$row->form_description, "form_json"=>$json_converter->form_json, "created_at"=>$row->created_at, "created_by"=>$row->created_by, "last_updated_at"=>$row->last_updated_at )); array_push($jadi_json, $saya); } header('content-type: application/json'); echo json_encode($jadi_json);
json format desired
{ "form": { "user_id": "1", "form_id": 26, "form_name": "kirenius", "form_description": "afafasf", "form_json": [{ "id": 72043, "name": "edittext", "input_type": "text", "hint": "", "options": "" }, { "id": "409289", "name": "ini spinner", "input_type": "spinner", "hint": "ini saya ro", "options": "saya, dan dia" }], "created_at": "17-10-2014_16:49", "created_by": "adminweb", "last_updated_at": "17-10-2014_16:49" } }
element arrays "[" , "]" omitted superficially need help.. thx god bless
first of all, json in list of form objects. parse json, utilize json_decode($json)
or cjson::decode($json)
. have array this:
array( 0 => array('form' => array(...)), // if there more `form` elements: 1 => array('form' => array(...)), );
to first element array, utilize $myarray[0]
or current($myarray)
(if don't know key first).
in end:
$myarray = cjson::decode($row->json_form); $saya = current($myarray); $secondsaya = next($myarray); $lastsaya = end($myarray);
if can controll json comes, seek alter it, comes single entry , not array. (e.g. cjson::encode(array('form' => array('user_id' => 1, /*...*/)))
javascript php json yii
No comments:
Post a Comment