Read data json inserted in mysql

0

I've seen many tutorials, and everyone includes [] but this one has not, is supposed to be missing something, can you help me? In the database is id date, id being the base code for each product which in turn has a calendar. I just need to have the id, where is by get, I have everything ready, but without the price I do not follow for paypal and have the project stuck for this. I do not do the minimum of how to read the data, I just want to have the id, which I already have and with the date of chek-in I can get the price, I just want it. if you prove me online that works, I pay for the script, it's urgent and I do not know what to do .. I really need it. I just need to go to this data, indicate the chekin for example 2016-06-16 and take the price nothing more.

{
  "2016-06-16": {
    "available": 6,
    "bind": 0,
    "info": "",
    "notes": "",
    "price": 878,
    "promo": 0,
    "status": "available"
  },
  "2016-06-17": {
    "available": 6,
    "bind": 0,
    "info": "",
    "notes": "",
    "price": 878,
    "promo": 0,
    "status": "available"
  } 
}
    
asked by anonymous 18.06.2016 / 06:05

1 answer

1

There is no problem with not having [] , it just means that your JSON object has only one collection of objects and there is no array in it.

You can access the value as follows:

$jsonString = '{"2016-06-16":{"available":6,"bind":0,"info":"","notes":"","price":878,"promo":0,"status":"available"},"2016-06-17":{"available":6,"bind":0,"info":"","notes":"","price":878,"promo":0,"status":"available"}}';

$jsonObject = json_decode($jsonString);

echo $jsonObject->{"2016-06-16"}->price;

See working at ideone

    
18.06.2016 / 06:16