0
我使用express js從mysql發送數據。我發送它使用res.json(theData)
。如何訪問此json對象
在客戶端,我得到它像這樣在控制檯:
{
"data":[
{
"PlazaID":1,
"PlazaName":"fff",
"PlazaAddress":"fff",
"PlazaContactNo":"45645",
"PlazaLanes":"34",
"PlazaStatus":"y",
"ClientID":1
},
{
"PlazaID":2,
"PlazaName":"plaza2",
"PlazaAddress":"p2",
"PlazaContactNo":"000",
"PlazaLanes":"2",
"PlazaStatus":"a",
"ClientID":2
}
],
"status":200,
"config":{
"method":"GET",
"transformRequest":[
null
],
"transformResponse":[
null
],
"url":"/getTollPlaza",
"headers":{
"Accept":"application/json, text/plain, */*"
}
},
"statusText":"OK"
}
我存儲這些值在數組中使用填充表angularjs' ng-repeat
這樣的:
for(i=0;i<response.data.length;i++){
tableArray.push({
plazaid:response.data[i].plazaid,
plazaname:response.data[i].plazaname,
plazaaddress:response.data[i].plazaaddress,
plazacontactnumber:response.data[i].plazacontactnumber,
plazalane:response.data[i].plazalane,
plazastatus:response.data[i].plazastatus,
clientid:response.data[i].clientid
});
}
當我console.log數組的值是未定義的。
0: Object
clientid:undefined
plazaaddress:undefined
plazacontactnumber:undefined
plazaid:undefined
plazalane:undefined
plazaname:undefined
plazastatus:undefined
其'ClientID'不是'clientid',javascript區分大小寫。 – shakib
JSON密鑰區分大小寫 解決它們,然後再試一次... –
是啊你的JSON密鑰是區分大小寫的,你已經把它叫做所有簡單的charectar plazaid:response.data [i] .plazaid在這裏它應該是數據[i ] .PlazaID這樣 –