【发布时间】:2020-06-25 11:03:43
【问题描述】:
我正在寻找一种有效的解决方案,将多个 json 数组合并为一个,并删除重复项。 我有多个具有这种结构的 json 文件:
[
{
"@_fa": "true",
"link": [],
"prism:url": "",
"dc:identifier": "ID-X",
"eid": "ID-X",
"dc:title": "",
"dc:creator": "",
"prism:publicationName": "",
"prism:issn": "",
"prism:eIssn": "",
"prism:volume": "",
"prism:issueIdentifier": "",
"prism:pageRange": "",
"prism:coverDate": "2020-05-01",
"prism:coverDisplayDate": "",
"prism:doi": "",
"dc:description": "",
"citedby-count": "0",
"affiliation": [],
"prism:aggregationType": "Jounal",
"subtype": "ar",
"subtypeDescription": "",
"author-count": {
"@limit": "100",
"@total": "5",
"$": "5"
},
"author": [],
"article-number": "",
"source-id": "",
"fund-no": "",
"fund-sponsor": "",
"openaccess": "0",
"openaccessFlag": false
},
{
...
}
]
我是这样读取这些文件的:
$json_1 = json_decode(file_get_contents('file_1.json'));
$json_2 = json_decode(file_get_contents('file_2.json'));
$json_3 = json_decode(file_get_contents('file_3.json'));
这些数组可以包含相同的元素,这些元素可以通过一些唯一字段来识别,例如 dc:identifier、eid、dc:title,它们都是唯一的。
我想将所有 $json_ 变量合并为一个,只保留一次不同数组之间的公共元素。什么是最好和最有效的解决方案?
【问题讨论】: