这就是我目前正在做的,以削减我所有的值(value)。它很难看,而且重复性太强。
var strHTML = '';
$.getJSON('info.php',
function(data) {
$.each(data, function(i, item) {
strHTML += $.trim(item.fname) +
$.trim(item.lname) +
$.trim(item.address) +
$.trim(item.phone) +
...(about 10 more of these);
});
});
应该有更好的方法来做到这一点。
最佳答案
for...in
示例,hasOwnProperty
:
var obj = {
foo: ' bar',
blahblah: ' ahahaha '
};
var arr = [];
for (key in obj) {
if (obj.hasOwnProperty(key)) {
arr.push($.trim(obj[key]));
}
}
alert(arr.join(','));
关于php - trim json 数据的最佳方法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5423188/