Read json data inserted in mysql

Asked

Viewed 207 times

0

I’ve seen many tutorials, and they all include [] but this one hasn’t, supposedly I’m missing something, can you help me ? In the database is id data, id being the base code for each product that in turn has a calendar. I just need to have the id, where it is by get, I have everything ready, but without the price I do not go to paypal and have the project stuck by this . I do not do the least how to read the data, I just want to have the id, I already have and with Chek-in date I can get the price, I just want it. If they prove to me online that it works, I pay for the script, it’s urgent and I don’t 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 withdraw 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"
  } 
}

1 answer

1

There’s no problem in not having [], means only that its object JSON 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 on ideone

  • You just saved my life, believe me. Thank you very much.

  • Take a look at the Tour, so you better understand how Stackoverflow works. Welcome.

  • Marcelo, would be interested in developing API integrations ?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.