我重視API在我的javascript其中有這樣的結果,當我通過郵遞員貼:解析JSON從API爲Javascript
{"result": {
"clientId": 1,
"session": "yJZdWRhIjoiSEExMDA4MzAyMCJ9.wrBz8JpNqMZlqv8Pz2Tx1x-XYecfdsH2B5uTbNPfiQE",
"client name": Andrew,
"address": [
["1","Bandung","West Java","Indonesia"],
["2","Depok","West Java","Indonesia"]
}
}
和這裏的API腳本:
var content='';
$.ajax({
type: "POST",
url:
rest_url+
'update/yJZdWRhIjoiSEExMDA4MzAyMCJ9.wrBz8JpNqMZlqv8Pz2Tx1x-XYecfdsH2B5uTbNPfiQE/'+_ClientId,
success: function (data) {
_Client = data;
}
});
我怎麼能添加json結果的內容填充這個空的var?
var address = ?????
var client_name = ?????
的jQuery已經解碼JSON響應轉換成常規的JavaScript對象。只要閱讀其他任何對象即可。 –
是的,所以將它添加到選項中:type:「POST」,dataType:「JSON」,url:... –
var address = data.result.address; var client_name = data.result.client_name' – Danmoreng