![](/img/trans.png)
[英]How do I print a barcode using barcode generator for PHP onto a pdf formatted page where I want it?
[英]How to select the barcode part of the JSON file I have using PHP?
我正在嘗試提取JSON文件中某些部分的信息,但無法獲取所需的部分。 目前,我專注於獲取條形碼,然后可以從那里確定如何做。
我嘗試了幾種不同的方法來嘗試選擇所需的數組部分,但無法弄清為什么它會因未定義索引而出錯:每次條形碼
<?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)
?>
我希望它顯示我的JSON文件中的條形碼部分。
{
"data": [
{
"baseSku": "71JNDAZA",
"sku": "71JNDAZA08",
"additionalSku": [],
"barcode": "889042766774",
"additionalBarcode": [],
"model": "71JND",
"title": "Arta Lace Ruffle Dress"
}
]
}
但是目前,我似乎無法從此處選擇任何內容。
正如克里斯·懷特(Chris White)提到的(只是正式回答), data
部分是一個數組,因此訪問它的正確方法是:
echo $data["data"][0]["barcode"];
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.