后台:
public partial class WMCData_mapTest_Default : System.Web.UI.Page
{
protected string strs = string.Empty;
protected void Page_Load(object sender, EventArgs e)
{
IList<QY_BASEINFOInfo> qys= QY_BASEINFOBLL.GetListByQuery("");
JavaScriptSerializer jss = new JavaScriptSerializer();
strs= jss.Serialize(qys);//list和单个object都可以直接序列化,如果是datetable的话找datetable转换为json格式的方法转换
}
}
前台:js数组
// 百度地图API功能
map = new BMap.Map("allmap");
map.centerAndZoom(new BMap.Point(117.422975, 32.510521), 10);
//var data_info = [[116.417854, 39.921988, "地址:北京市东城区王府井大街88号乐天银泰百货八层"],
// [116.406605, 39.921585, "地址:北京市东城区东华门大街"],
// [116.412222, 39.912345, "地址:北京市东城区正义路甲5号"]
//];
var m = ‘<%=strs%>‘;后台读取json格式的字符串
m = $.parseJSON(m);转换为json对象
alert(m.length);
var data_info = new Array();//新建数组
for (var i = 0; i < m.length; i++)
{
var arr1 = new Array();//新建数组
arr1[0] = m[i].FRDB;
arr1[1] = m[i].WD;
arr1[2] = m[i].DWMC;
data_info[i] = arr1;
}