我用这个方法来产生一通一通:
如何产生2个不同json_encodes
public function setJSON($JSON) { if(json_decode($JSON) !== false) { $this->JSON = $JSON; return true; } $this->sError = 'This is not a JSON string.'; return false; }我把这种方法生成的通:
$pass->setJSON('{ "passTypeIdentifier": "'.$passTypeID.'", "formatVersion": 1, .............. "barcode": { "altText" : "'.$alt.'", "format" : "PKBarcodeFormatPDF417", "message": "Member-Card", "messageEncoding": "iso-8859-1", "changeMessage" : "This pass now has altText %@ !" }, "locations" : [ { "longitude" : 104.89529371261597, "latitude" : 11.576150037278605, "relevantText": "CamMob (dis. 1%)" }, ..................... ] }');但现在我不写静态的位置,我也得到那些来自数据库的数据通过:
$query5 = mysql_query("select * from company");
while ($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方法的问题吗?如果我喜欢这样,我怎么能把这两个jsons结合在一起?
多少地方,你呢?请记住,只有前10个会显示。另外,如果您想验证位置是否被添加到JSON中,您可以将.pkpass文件的扩展名更改为.zip以查看您的代码正在生成的内容,或者将JSON写入php日志。 – PassKit 2013-05-10 01:40:22
如果我从数据库中选择位置,如何通过编码将它们添加到已创建的通道中? – malinchhan 2013-05-10 01:58:11
我不知道如何结合不同的encode_json! – malinchhan 2013-05-10 02:04:58