php - how to pass value of varibles in json -
foreach ($orderslist $object) { $entityid = $object->entity_id; //how give $entityid in json $json='{ "orderno":$entityid, //here want assign value of $entityid "customercode": $customerid, "dateordered": "08-07-2015", "warehouseid" : , "orderlinelist": [ "productid": 1000002, "qty": 6, "price": 10 ] }'; } $data = json_decode($json); $data_string= json_encode($data);
don't write json strings hand.
$data = [ "orderno" => $entityid, //here want assign value of $entityid "customercode" => $customerid, "dateordered" => "08-07-2015", "warehouseid" => null , "orderlinelist" => [ "productid": 1000002, "qty": 6, "price": 10, ], ]; $json = json_encode($data); json_decode() give error this:
{"orderlinelist": [ "productid": 1000002 ]}
Comments
Post a Comment