一、前台
var myObject = JSON.parse(_data);
alert("对象:"+myObject.msg);
alert("对象:"+myObject.msg);
// 转换成数组
var myobj = eval("["+_data+"]");
for (var i = 0; i < myobj.length; i++) {
alert("数组:"+myobj[i].msg);
}
//把json格式的字符串转成JSON对象
var json1 = '{"department": "中兵","address": "北京","contacts": "李硕","telphone": "15201274666","email": "li_shilei@yeah.NET","fax": "0108596666"}';
var json2 = '{"department": "中兵2","address": "北京2","contacts": "李硕2","telphone": "152012746662","email": "li_shilei2@yeah.Net","fax": "01085966662"}';
var jsonObj = $.parseJSON(json1); 或用eval方法
//把数组转成JSON对象
var arr=new Array();
arr.push(json1);
arr.push(json2);
var b=JSON.stringify(arr)
二、后台
当需要把一串字符串转成一个json 数组 ,并遍历其中的内容时。
首页导入 net.sf.json.JSONArray和net.sf.json.JSONObject 两个jar 包
0){
for(int i=0;i属性值
}
}