【发布时间】:2018-04-19 13:32:03
【问题描述】:
我有一个 JSON 数组,如下所示:-
[{
"order_no": "1",
"contract_no": "DCI-92700028",
"dc_in_date": "2017-11-06",
}, {
"order_no": "1",
"contract_no": "DCI-92700028",
"dc_in_date": "2017-11-06",
}, {
"order_no": "G1049",
"contract_no": "DCI-37500029",
"dc_in_date": "2017-11-06",
}]
我想创建将包含所有类似contract_no 的键值对的数组数量。对于上面的示例,我想要输出如下:-
数组-I
[{
"order_no": "1",
"contract_no": "DCI-92700028",
"dc_in_date": "2017-11-06",
}, {
"order_no": "1",
"contract_no": "DCI-92700028",
"dc_in_date": "2017-11-06",
}]
和
数组-II
[ {
"order_no": "G1049",
"contract_no": "DCI-37500029",
"dc_in_date": "2017-11-06",
}]
基本想法是我有两列的 Mysql 表。一个是“contract_no”,另一个是“order_details”。我想将 order_details 的值更新为合同编号匹配的 Array-I 和 Array-II。
有没有办法做到这一点?
【问题讨论】:
-
Is there a way to do this?当然有。到目前为止,我没有看到你尝试过的任何东西。那么,到目前为止,您尝试过什么? -
我尝试了 if else。如果合约编号与数组的先前合约编号匹配,则推入一个新数组,否则循环将继续下一个。但问题是它只创建了一个不等于匹配对数的数组。
-
只需检查该 json 数组中有多少对象。根据您的需要..