【问题标题】:Aggregating JSON output聚合 JSON 输出
【发布时间】:2016-08-28 05:23:22
【问题描述】:

我在 PHP 上有一个 JSON 输出,例如:

[{"Title":"Message","count":"180","Number":"200"},
 {"Title":"Message","count":"200","Number":"400"}]

如何获得如下结果?

[{"Title":"Message","count":"380","Number":"600"}]

【问题讨论】:

标签: php json


【解决方案1】:

在php中:

json_encode(array_merge(json_decode($a, true),json_decode($b, true)))

参考:example

【讨论】:

  • 感谢您的回复,但它仍然返回重复值,我想按“消息”分组并将“计数”和“数字”相加
猜你喜欢
  • 1970-01-01
  • 2013-01-04
  • 2015-09-13
  • 1970-01-01
  • 1970-01-01
  • 2018-09-02
  • 1970-01-01
  • 2023-03-08
  • 1970-01-01
相关资源
最近更新 更多