我有這樣的代碼,如何獲得長度字符串JSON在JS或jQuery的
buildSelect: function (data) {
var response = $.parseJSON(data);
alert(response.length);
var s = "<select>";
if (response && response.length) {
for (var i = 0, l = response.length; i < l; i++) {
var ri = response[i];
s += '<option value="' + ri.CUSTOMS_ID + '">'
+ ri.CUSTOMS_NAME + '</option>';
}
}
return s + "</select>";
}
},
我想查詢響應不爲空或空,並得到長度我寫這篇文章的代碼response.length
但返回undifine
並返回數據
{"rows":[{"id":1,"cell":["1","بندرامام خميني","IMAM KHOMEINI PORT","True",null]},{"id":2,"cell":["2","آبادان","ABADAN","True",null]},{"id":3,"cell":["3","خرمشهر","KHORRAMSHAHR","True",null]},{"id":4,"cell":["4","بندرعباس","BANDAR ABBAS","True",null]},{"id":5,"cell":["5","بوشهر","BUSHEHR","True",null]},{"id":6,"cell":["6","تهران","TEHRAN","True",null]},{"id":7,"cell":["7","شيراز","SHIRAZ","True",null]},{"id":8,"cell":["8","دبي","DUBAI","True",null]}],"Page":0,"Total":0,"Records":0}
我想如果行不爲空,所有的子項添加到下拉列表
plese幫助我,謝謝
函數(數據)中的數據是否已經是JSON對象? – 2012-04-03 06:36:35
'空'是什麼意思?這個'{}''? – Engineer 2012-04-03 06:46:56
如果行不是子例子[{「id」:1,「cell」:[「1」,「بندرامامخميني」,「IMAM KHOMEINI PORT」,「True」,null]},... – Pouya 2012-04-03 06:49:28