I am trying to pull certain parts of information I have in a JSON file but unable to get the parts I want. At the moment I am focusing on getting barcode and can then work out how to do it from there.
I have tried several different ways to trying to select the part of the array I want but cannot work out why it errors with Undefined index: barcode every time
<?php
$host="localhost";
$username="root";
$password="root";
$dbname="demo";
//create a Connection
$conn=mysqli_connect($host,$username,$password,$dbname);
//check the connection
if(!$conn)
{
die("connection does not established successfully :".mysqli_connect_error());
}
//read the json file using php method file_get_contents('filename.json')
$jsondata=file_get_contents('file.json');
//convert json into php array
$data=json_decode($jsondata,true);
//get the details of student from JSON file and store it in the variable one by one.
$id=$data['data']['barcode'];
print_r($id)
?>
I expect it to show the barcode section from my JSON file.
{
"data": [
{
"baseSku": "71JNDAZA",
"sku": "71JNDAZA08",
"additionalSku": [],
"barcode": "889042766774",
"additionalBarcode": [],
"model": "71JND",
"title": "Arta Lace Ruffle Dress"
}
]
}
But at this moment I seem unable to select anything from in here.