我使用此方法生成通行证:
公共函数 setJSON($JSON) { 如果(json_decode($JSON)!== 假){ $this->JSON = $JSON; 返回真; } $this->sError = '这不是 JSON 字符串。'; 返回假; }我调用这个方法来生成传递:
$pass->setJSON('{ "passTypeIdentifier": "'.$passTypeID.'", “格式版本”:1, ..................... “条码”: { "altText" : "'.$alt.'", "格式" : "PKBarcodeFormatPDF417", "message": "会员卡", "messageEncoding": "iso-8859-1", "changeMessage" : "这个 pass 现在有 altText %@ !" }, “地点”:[ { “经度”:104.89529371261597, “纬度”:11.576150037278605, "relevantText": "CamMob (dis. 1%)" }, ..................... ] }');但是现在我不会静态地编写这些位置,而是通过以下方式从数据库中获取这些数据:
$query5 = mysql_query("select * from company");
而 ($row5 = mysql_fetch_array($query5)){
$companyName = $row5['relevantTextName'];
$discount = $row5['relevantTextDiscount'];
$long = $row5['longitute'];
$lat = $row5['latitute'];
$link = $row5['link'];
$location['locations'][] = array("longitute" => $long, "latitute" => $lat, "relevantText" => $companyName." (" . $discount. "%)" );
}
$jsonString = json_encode($location) ;
error_log("Locations: ".$jsonString,0);
$pass->setJSON($jsonString);
$pass->setJSON('{
"passTypeIdentifier": "'.$passTypeID.'",
"barcode": {
"altText" : "'.$alt.'",
"format" : "PKBarcodeFormatPDF417",
"message": "Member-Card",
"messageEncoding": "iso-8859-1",
"changeMessage" : "This pass now has altText %@ !"
}
}');</pre>
测试更新通行证时没有错误,但我无法像以前那样在锁定屏幕上看到通行证。因此,这意味着我尚未将这些位置包含在通行证中。我应该改变什么?是方法 setJSON 的问题吗?如果我这样做,我怎样才能将这 2 个 json 组合在一起?