首先,我有兩個API URL: http://example.com/api/list它輸出一個版本列表和散列作爲ID。獲取併合並多個json請求,編號爲
[
{
"versions": [
{
"version": "1.0",
"hash": "15ac8f7dfcef3f3b9b3b5a48a7bee327",
},
{
"version": "1.1",
"hash": "5990bf1b3f11225d970c5d266e77e641",
}
]
}
]
然後http://example.com/api/version通過POST請求,它使用哈希來提取版本細節。換句話說,當GET請求:/ API /版本/ 15ac8f7dfcef3f3b9b3b5a48a7bee327這是輸出:
[
{
"id": "1",
"name": "Example",
"type": "version",
"version": "1.0",
"file_name": "testfile.txt",
"hash": "15ac8f7dfcef3f3b9b3b5a48a7bee327",
}
]
我試圖做的是做一個foreach循環來讀取API/URL列表的哈希值並獲取所有版本的細節,他們都在編碼回JSON輸出將顯示合併成一個數組方式:
[
{
"id": "1",
"name": "Example1",
"type": "version",
"version": "1.0",
"file_name": "testfile1.txt",
"hash": "15ac8f7dfcef3f3b9b3b5a48a7bee327",
},
{
"id": "2",
"name": "Example2",
"type": "version",
"version": "1.1",
"file_name": "testfile2.txt",
"hash": "5990bf1b3f11225d970c5d266e77e641",
}
]
我不能完全肯定,因爲我是如何與foreach循環做到這一點使用來自一個json請求的值來調用API並獲得另一個。
你是如何獲得這些JSON響應?通過捲曲或ajax? –