I already possessed variable JSON encoded, then there are elements in the json array like "[" and "]". the question is? how to remove the element.
This is an example of the 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 as $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 "[" and "]" are omitted only superficially.