JQ将数组转换为Json

时间:2022-04-28 00:11:06
var ArrComList;
try {
//接口传进来的数据格式为 A,B,C,D,这里根据逗号分隔返回数组。
ArrComList = WeighControl.GetComList().split(',');
} catch (e) { }
var s = "";
//循环将数组转换为Json格式。
for (var i = 0; i < ArrComList.length; i++) {
if (s.length > 0) { s += "," };
s += "{\"id\":" + i + ",\"text\":\"" + ArrComList[i] + "\"}";
}
s = eval("[" + s + "]"); //将Json的数据赋值给Combox
$("#weighInterface").combobox("loadData", s);