识别由不同数量的项组成的json对象
identify json object consisting of different number of items
这是我的json
对象
[
{
"grup":"",
"barkod":"1234",
"amount":"1",
"selling price":"215",
"cost":"68.69"
},
{
"grup":"4444",
"barkod":"",
"ammount":"1",
"selling price":"49.9",
"cost":"75"
},
{
"grup":"3333",
"barkod":"091986 ",
"amount":"1",
"selling price":"69.9",
"cost":"16.56"
},
{
"cost":"300",
"pay type":"cash",
"taksit":"1"
},
{
"cost":"200",
"pay type":"BANK",
"taksit":"7"
},
{
"idNo":""
}
]
这个对象是通过ajax php服务器发送的。然后,将其转换为php数组:
$datax = json_decode(file_get_contents("php://input"));
我想要前3个元素(数量可以改变)运行CCD_ 2的插入语句,对于4。和5。元素为table2
运行插入语句,依此类推
如果你想打印第一个对象,你应该使用这个:
print_r(datax[0]);
我在这里为MySQL编写了一个示例语句,所以您可以为自己的代码编辑它。
$grup = $datax[0]->grup;
$firma_barkod = $datax[0]->firma_barkod;
$adet = $datax[0]->adet;
$birim_satis_fiyati = $datax[0]->birim_satis_fiyati;
$birim_maliyet = $datax[0]->birim_maliyet;
$query = "INSERT INTO table_name (grup, firma_barkod, adet, birim_satis_fiyati, birim_maliyet)
VALUES ('$grup', '$firma_barkod', '$adet', '$birim_satis_fiyati', '$birim_maliyet');
我只是想让你理解其中的逻辑;如果要到达第一个元素,则应使用$datax[0]
,如果要到达第四个元素,应使用$datax[3]
相关文章:
- jQuery匹配JSON对象的部分文本
- 如何在Javascript中将JSon对象转换为数组
- 我可以在json对象中添加一个函数吗
- 使用JS将数组转换为json对象
- 如何为json对象中的段发送array[]
- 将JSON对象传递给angular指令
- 更改JSON对象的结构
- 访问JSON对象内部的数组元素
- 在ejs-partial中对JSON对象进行迭代
- 遍历 JSON 对象并检查 URL 是否以某个值结尾
- 访问嵌套JSON对象的键,其中键是动态的
- json对象中缺少对象循环
- 发送json对象或使用express路由呈现视图
- 在play2框架中向json对象添加下拉列表项
- 元素名称上带有短划线 (-) 字符的 Json 对象
- autocomplete不接受源的json对象
- 如何在javascript中创建动态json对象
- 在使用客户端脚本时拾取JSON对象
- 如何通过json对象数组为嵌套对象赋值
- 构造JSON对象