4
是json/javascript中的新手,請耐心等待。我從一個加載API URL獲取JSON數據某物像將json數據從api傳遞給javascript變量
{
"employees": [
{ "firstName":"John" , "lastName":"Doe" },
{ "firstName":"Anna" , "lastName":"Smith" },
{ "firstName":"Peter" , "lastName":"Jones" }
]
我需要它作爲一個腳本文件
var employess={
"employees": [
{ "firstName":"John" , "lastName":"Doe" },
{ "firstName":"Anna" , "lastName":"Smith" },
{ "firstName":"Peter" , "lastName":"Jones" }
]
}
大道試圖
$.getJSON(myUrl",function(data){ $("#selector").data("JSONP",data); alert(data); });
JSON是一種字符串格式,而不是Javascript對象。 'var object = JSON.parse(jsonString)'https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/JSON/parse – jrajav
你有什麼問題? – SLaks
'employees = data'? – sje397