我想将 json 数组与另一个从 URL 访问的 json 数组合并。
example1.json
"contents":[
{
"idSentence":[
118077
],
"idParagraph":16424
},
{
"idSentence":[
10402,
85562
],
"idParagraph":16427
},
]
例如, http://www.example.com/2016/04/news/idS/10402/f/json将返回:
"idSentence":10402,
"sentence":"Compact but strong storms known as supercells reach Oklahoma, "
和http://www.example.com/2016/04/news/idS/85562/f/json将返回:
"idSentence":85562,
"sentence":"which also brought many violent storms to the states of Kansas, Arkansas, and Tennessee."
我的问题是,如何将 json 与 PHP 和 JS 结合起来显示,如下所示?
Id Paragraph Id Sentence Sentence
16427 10402 Compact but strong storms known as supercells reach Oklahoma,
16427 85562 which also brought many violent storms to the states of Kansas, Arkansas, and Tennessee
有很多句子和段落,所以我需要一种有效的方法来做到这一点。 我的想法是通过检索每个 id 段落中的 id 句子,并调用与 id 句子对应的句子的 json url,将两者结合起来,然后将其显示到表中进行迭代过程
$jsonText = file_get_contents("example.json");
$jsonUrl = "http://www.example.com/2016/04/news/idS/idSentence/f/json"
$arr = json_decode($jsonText, true);
//This is the part of iterative process & call correspond id sentence
//This is the part of combining process and show it to table
我是 json 的相对初学者,所以我仍然对如何解决这个问题感到困惑。 请帮忙,谢谢。
最佳答案
当你解码 json 时,你将得到一个数组。将数组与 array_merge_recursive 组合起来并使用 json_encode write inside the file 对该数组进行编码.
关于javascript - 如何使用 PHP 和 JS 将 URL 中的 json 数组与另一个 json 数组组合起来,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43936389/