Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

foreach ($ordersList as $object) {

    $entityid = $object->entity_id; //how to give this $entityid with in json

    $json='{
    "orderNo":$entityid,          //here i want to assign the 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);
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
233 views
Welcome To Ask or Share your Answers For Others

1 Answer

Don't write JSON strings by hand.

$data = [
    "orderNo" => $entityid, //here i want to assign the value of $entityid
    "customerCode" =>  $customerid,
    "dateOrdered" => "08-07-2015",
    "warehouseId" => null ,
    "orderLineList" => [
        "productId": 1000002,
        "qty": 6,
        "price": 10,
    ],
];

$json = json_encode($data);

json_decode() would give an error for this:

{"orderLineList": [ "productId": 1000002 ]}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...