php - How to generate a pass from 2 different json_encodes -


i use method generate pass:

 public function setjson($json) {     if(json_decode($json) !== false) {         $this->json = $json;         return true;     }     $this->serror = 'this not json string.';     return false;     } 
call method generate pass by:
$pass->setjson('{     "passtypeidentifier": "'.$passtypeid.'",     "formatversion": 1,     .............. "barcode": {         "alttext" : "'.$alt.'",         "format" : "pkbarcodeformatpdf417",         "message": "member-card",         "messageencoding": "iso-8859-1",         "changemessage" : "this pass has alttext  %@ !"         }, "locations" : [     {       "longitude" : 104.89529371261597,       "latitude" : 11.576150037278605,       "relevanttext": "cammob (dis. 1%)"     },      ..................... ]     }'); 
don't write locations statically , data database :
$query5 = mysql_query("select * 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 has alttext %@ !" } }');</pre>

there no error when test updating pass, cannot see pass on lock screen before. means not yet include locations pass. should change ? problem of method setjson ? if this, how can combine these 2 jsons become ?

rather constructing json directly, construct array first, transform json.

$pass_data = array("passtypeidentifier" => $passtypeid,                    "formatversion" => 1,                    "barcode" => array (                                        "alttext" => $alt,                                        "format" => "pkbarcodeformatpdf417",                                        "message" => "member-card",                                        "messageencoding" => "utf-8", // use utf8 in case want encode khmer or other non ascii                                         "changemessage" => "this pass has alttext  %@ !"                                       ),                     "locations" => $locationsarray,                    "organizationname" => "digi club card",                    "description" => "membership card",                    "logotext" => "digiclub",                    "foregroundcolor" => "rgb(0,0,0)",                    "backgroundcolor" => "rgb(211,211,211)",                    "generic" => array (                             "headerfields" => array(                                        array ( "key" => "status",                                                "label" => " ",                                                "value" => "membership card"                                              ),                                        ),                             "primaryfields" => array(                                        array ( "key" => "name",                                                "value" => $membername,                                              ),                                        ),                              "secondaryfields" => array(                                       // secondary field data                                        ),                              "auxiliaryfields" => array(                                       // auxiliary field data                                        ),                              "backfields" => array(                                       // backfiels field data                                        ),                            )                     ); 

then transform array json:

$pass->setjson(json_encode($pass_data)); 

Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -