I made an API call and received the response in JSON format.
JSON:
{
"Specialities": [
{
"SpecialityID": 1,
"SpecialityName": "Eye Doctor"
},
{
"SpecialityID": 2,
"SpecialityName": "Chiropractor"
},
{
"SpecialityID": 3,
"SpecialityName": "Primary Care Doctor"
}
]
}
Controller File:
public function index(){
$data= json_decode(file_get_contents('some_url'));
$this->load->view('my_view',$data);
}
Above code doesn't work because in view I can't access the nested object properties. However I am able to echo the JSON properties in controller file just like this:
Controller File:
public function index(){
$data=json_decode(file_get_contents('some_url'));
foreach ($data as $key=>$prop_name){
for($i=0;$i < count($prop_name);$i++){
echo $prop_name[$i]->SpecialityID;
echo $prop_name[$i]->SpecialityName;
}
}
}
My question is how do I pass this JSON to view and how can I access those properties in view file?