![]() ![]() ![]() $data = 'Please configure your database correctly' $data = 'Json data successfully inserted into database !' $return = $this->json_model->insert_json_in_db($json_data) 'employee_address' => $this->input->post('address'), 'employee_gender' => $this->input->post('select'), 'employee_email' => $this->input->post('emp_email'), 'employee_name' => $this->input->post('emp_name'), Otherwise, json_decode() will return NULL.// Fetch user data and convert data into json While passing an associative array or object with key and value pair for json_decode(), the key value should be enclosed in double-quotes.Resultant decoded array data from JSON object: ![]() Resultant decoded object data from JSON object: Print "Resultant decoded array data from JSON object:" Īfter that, on executing this code, the following output will be returned to the browser. $str_jsonAry_decoded = json_decode($obj_json_format, true) Print "Resultant decoded object data from JSON object:" $str_objJson_decoded = json_decode($obj_json_format) Resultant decoded array from JSON array:" With the above PHP example program, we need to append the following lines. And, the PHP supported constantly for the option parameter of this function is, JSON_BIGINT_AS_STRING, which is used to convert long integers into float data. The default value for the depth limit is 512. The third and fourth arguments are the same as we have seen for json_encode(). The Boolean value set is based on which an associative array will be returned if it is true.This function accepts four arguments as listed below. This is the reverse operation of JSON encode, obviously used to convert JSON encoded data into its original PHP data type from where it is encoded initially.įor that, the second method json_decode() we have listed at the beginning of this article, will be used. While using JSON_FORCE_OBJECT on encoding PHP array value, then each array element will be added to an index even if the input array doesn’t have an index.PHP json_encode() is used to convert any type of data except PHP resource data.Print "JSON Formatted String with white space:". $strJsonFormat_with_space = json_encode($input_array, JSON_PRETTY_PRINT) So, the following program handles a few json_encode() functions invoked with some of the available JSON encode constants as its options parameter. Now, it’s time to see an example PHP program to perform JSON encoding. JSON_UNESCAPED_UNICODE – It prevents from escaping Unicode characters.JSON_UNESCAPED_SLASHES – It prevents escaping slashes (/).JSON_PRETTY_PRINT – pretty print is used for adding white space with the JSON formatted data.JSON_BIGINT_AS_STRING – This constant is used to convert the log integer value as a string.JSON_NUMERIC_CHECK – PHP JSON encode function will return numbers as a result of encoding given a number with the string data type.JSON_FORCE_OBJECT – Using this, json_encode will return an object for given input data except for the associative array.JSON_HEX_QUOT – converts double quotes (“) into \u0022.JSON_HEX_APOS – encode apostrophe (‘) with \u0027.JSON_HEX_AMP – Used to encode data by replacing ampersand symbol (
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |