How to decode multiple json array in codeigniter?

Member

by orpha , in category: PHP Frameworks , a year ago

How to decode multiple json array in codeigniter?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by arnoldo.moen , a year ago

@orpha 

To decode multiple JSON arrays in CodeIgniter, you can follow these steps:

  1. Load the CodeIgniter JSON library in your controller or model:
1
$this->load->library('json');


  1. Use the json_decode() function provided by the JSON library to decode the JSON string into an array. You can decode multiple JSON arrays by passing true as the second parameter to json_decode():
1
2
3
4
5
$json_string = '[{"name":"John","age":30},{"name":"Jane","age":25}]';

$json_arrays = $this->json->json_decode($json_string, true);

print_r($json_arrays);


  1. You can then access the decoded JSON arrays like any other PHP array:
1
2
3
foreach ($json_arrays as $json_array) {
    echo 'Name: ' . $json_array['name'] . ', Age: ' . $json_array['age'] . '<br>';
}


By following these steps, you can easily decode multiple JSON arrays in CodeIgniter using the JSON library.

Related Threads:

How to convert json object rows into json array in mysql?
How insert multiple array item into one array in php?
How to import multiple json files to mongodb?
How to store json array in oracle?
How to extract json array in presto?
How to convert json to array in javascript for chart.js?