我有這個函數可以獲取JSON對象。如何在javascript中格式化JSON輸出
function dataFetch(){
const url = "http://www.quotzzy.co/api/quote?key=436587";
fetch(url).then(function(response) {
return response.text();
}).then(function(text) {
console.log('Request successful', text);
}).catch(function(error) {
log('Request failed', error)
});
};
如何返回單獨的JSON對象中的索引以在HTML中使用?
贊,我的名字(object.name
)和我的報價是(object.text
)從這個信息源(object.source
)。
'JSON.parse'和'JSON.stringify'可用於串和JSON格式之間隱蔽。您可以閱讀response.text(),然後閱讀感興趣的特定屬性。 –
我已經使用了這兩個,我更喜歡JSON.parse();但我如何提取該數據在HTML中使用,我試過沒有成功的循環,我得到了未定義。 – RhodosCoder
你的問題相當廣泛。您能否提供一個具體的數據示例,以及您想要在HTML中產生的結果? (編輯你的問題) – trincot