【发布时间】:2017-10-11 16:39:52
【问题描述】:
我想将 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的相对初学者,所以我仍然对如何解决这个问题感到困惑。 请帮忙,谢谢。
【问题讨论】:
标签: javascript php html arrays json