![]() |
Restfull JSON Array Help - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24) +--- Thread: Restfull JSON Array Help (/showthread.php?tid=64885) |
Restfull JSON Array Help - BeVirtual - 04-07-2016 Hi, Please can someone give me some advice, I have setup an API which is working but cant seem to get some of the json data. this is the data being posted(cant be changed coming from out side source) { "code": "VET002", "store": "DBNG0024", "items": [ { "code": "1", "descr": "Yoghurt", "value": "66", "qty": "3", "dept": "1" }, { "code": "25", "descr": "Red Bull", "value": "44", "qty": "2", "dept": "2" }, { "code": "23", "descr": "Lipton Lemon", "value": "72", "qty": "6", "dept": "2" } ] } this is how I'm reading the data $code = $this->post('code'); $store_code = $this->post('store'); $total = $this->post('total'); how would i read the items values. Thank you RE: Restfull JSON Array Help - EricP - 04-07-2016 (04-07-2016, 12:03 AM)Try Wrote: RE: Restfull JSON Array Help - BeVirtual - 04-07-2016 (04-07-2016, 02:44 AM)EricP Wrote:(04-07-2016, 12:03 AM)Try Wrote: thanks for your reply sorry but I'm still bit confused about this part PHP Code: $input = $_REQUEST['your_request_data_name']; //Set this in your javascript (ajax request) the data is coming from an external source that is connecting to out api. the api is working I just not sure how to access the items array. when I echo items all it prints is the word "Array" RE: Restfull JSON Array Help - Tpojka - 04-07-2016 You can't "echo" an array. Language construct "echo" is used to output one or more strings. Use print_r instead and you could see what is in array. RE: Restfull JSON Array Help - BeVirtual - 04-07-2016 (04-07-2016, 05:11 PM)Tpojka Wrote: You can't "echo" an array. Language construct "echo" is used to output one or more strings. Hi Tpojka, Sorry it I used the wrong term i dont mean echo, I'm just trying to figure out how to get the values within the "items" array. I can get the code and the store, but when I try get "items" all i get is the word "Array"(when using print_r) Hope I have explained myself correctly this time. please bare with me I'm new to all this. RE: Restfull JSON Array Help - paulkd - 04-08-2016 Hope this helps. PHP Code: $json = ' RE: Restfull JSON Array Help - BeVirtual - 04-08-2016 (04-08-2016, 01:17 AM)paulkd Wrote: Hope this helps. that does help a lot problem is that I dont have the json data its coming from an external source. so not sure what I would replace $json with. might be helpful to mention im using rest server. thanks again really appreciate the help RE: Restfull JSON Array Help - paulkd - 04-08-2016 Is the "external source" available publicly or is it private? RE: Restfull JSON Array Help - BeVirtual - 04-08-2016 (04-08-2016, 02:11 AM)paulkd Wrote: Is the "external source" available publicly or is it private? its private... basically a another company sends data in json array format to our api url |