我已經使用JSONP從另一個源獲取數據,該數據返回一個單詞列表以隨機取出其中一個用於遊戲中的單詞......我的源代碼看臺是;隨機從JSON字符串中選擇一個單詞
function processResult(obj) {
console.log(obj);
var blah = JSON.stringify(obj);
console.log(blah);
}
var jsonp = document.createElement('script');
jsonp.src = 'http://testhangmangame.net76.net?jsonp=processResult';
document.body.appendChild(jsonp);
我想知道,如果以及如何從字符串中提取一個字先謝謝了!
JSON的實施例返回:
{
"words": [
"Finitely",
"Misleading",
"Dinning",
"Energizing",
"Untruest",
"Menorah",
"Ghoulish",
"Realism",
"Caliphate",
"Buttercup",
"Oratorio",
"Prefix",
"Gaming",
"Preshrunk",
"Harmed",
"Loop",
"Banknote",
"Doily",
"Rest of words removed"
]
}
此JSON被包裹在processResult(...);
。
你的控制檯輸出是什麼樣的? – ctcherry
可能的重複[如何從數組中返回一個隨機值?](http://stackoverflow.com/questions/3419928/how-can-i-return-a-random-value-from-an-array) – Barmar
請發佈服務器響應示例。我相信你的問題與JSON無關(JSONP實際上與JSON沒有任何關係)。 –