如何通过在JSON可变因素的价值 [英] how to pass value of varibles in json
本文介绍了如何通过在JSON可变因素的价值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
的foreach($ ordersList为$对象){ $ ENTITYID = $对象 - > ENTITY_ID; //如何给这个$ ENTITYID与JSON $ JSON ='{
orderNo:$ ENTITYID,//在这里,我要分配的$ ENTITYID价值
以客户为code:$客户ID,
dateOrdered:2015年8月7日,
warehouseId:,
orderLineList:
[ 的productId:1000002,
数量:6,
价格:10
]
};
}$数据= json_de code($ JSON);
$ data_string = json_en code($的数据);
解决方案
不要手工编写JSON字符串。
$数据= [
orderNo=> $ ENTITYID,//在这里,我要分配的$ ENTITYID价值
以客户为code=> $客户ID,
dateOrdered=> 2015年8月7日
warehouseId=>空值 ,
orderLineList=> [
的productId:1000002,
数量:6,
价格:10,
]
];$ JSON = json_en code($的数据);
json_de code()会给出一个错误是:
{orderLineList:[的productId:1000002]}
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);
解决方案
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 ]}
这篇关于如何通过在JSON可变因素的价值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文