javascript - How to remove element array "[" & "]" in json? -


I already had variables JSON encoded, then there are elements in the json array like "[" and "]". The question is

<> [{"form": {"user_id": "1", "form_id")

: "text", "hint", "form_name": "rays "", "Form_ description": "Effect", "Form_Jason": [{"ID": 72043, "Name": "Edit Text", "Input_type": "Text", "Indication": "", "Options" "Ina ca. RO", "Options": "Saya, Dan Diya"}], "", "", "409289", "name": "spinner", "input_type": "spinner", "sign" Created ":" 17-10-2014_16: 49 "," created ":" adminweb "," last_updated_at ":" 17-10-2014_16: 49 "}}]

PHP:

  $ jadi_json = array (); Forex currency ($ model $ line) {$ json_conver Ter = json_decode ($ line-> json_form); $ saya = array ("form" => array ("user_id" => = row-> id_user, "form_id" => $ Row-> id_form, "form_name" = & gt; $ line-> form_name, "form_description" = & gt; $ row-> form_description, "form_json" => gt; json_converter- & gt; Form_json, "created_at" = & gt; $ line- & gt; created_it, "created =" => $ row- & gt; Created, "last_updated_at" = & gt; $ Row-> Last_transfer_at)); Array_push ($ jadi_json, $ saya); } Header ('Content-Type: Application / Jason'); Echo json_encode ($ jadi_json);  

json format desired

  {"form": {"user_id": "1", "form_id": 26, "form_name": "Kiranius "Text", "hint": "," "option": "fax", "form_ jason": [{"id": 72043, "name": "edit text", "input_type" "In", "name": "409289", "name": "in-spinner", "input-type": "spinner", "hint": "ini sina ro", "option": "shyya, don diya "}", "Created_t": "17-10-2014_16: 49", "created": "adminweb", "last_updated_at": "17-10-2014_16: 49"}}  

Element arrays "[" and "]" are only omitted from the over effect.

Before parsing, use the json_decode ($ json) or CJSON :: decode ($ json) to parse JSON in your JSON form objects list. This type of array will be:

  array (0 = & gt; array ('form' => array (...), // if any more `form ' Element is: 1 = & gt; array ('form' = & gt; array (...));  

To get the element before the array, Use $ myArray [0] or current ($ myArray) (if you do not know that Will) from before.

Finally:

  $ myArray = CJSON :: decode ($ line-> json_form); $ Say = current ($ myArray); $ Secs = next ($ myArray); $ LastSaya = end ($ myArray);  

If you can control from where you come from your JSON, try changing it, so it comes in the form of a single entry and not in the form of an array. (E.g. CJSON :: encoded (array ('form' => array ('user_id' => 1 / / ... ..)))] / code>


Comments

Popular posts from this blog

winforms - C# Form - Property Change -

java - Messages from .properties file do not display UTF-8 characters -

javascript - amcharts makechart not working -