
json 解析集合里面对象点数据的时候出错。。求解??是不能点属性吗?
publicStringdoQueryProvince()throwsException{Longid=Long.parseLong(request.getParamet...
public String doQueryProvince()throws Exception{
Long id=Long.parseLong(request.getParameter("id"));
MCountryareaVO country=new MCountryareaVO();
country.setCaId(id);
List<MProvinceVO> provinceList=provinceService.queryProvinceNames(country);
JSONObject obj=new JSONObject();
obj.put("provinceList", provinceList);
response.getWriter().write(obj.toString());
return null;
}
function doBaseCountry(){
var id=$("#country").attr("value");
$.getJSON("<c:url value='/baseInfo/airlinesAction_doQueryProvince.do'/>?id="+id,null,function(data){
for(var i=0;i<data.provinceList.length;i++){
alert(data.provinceList[i].name);
}
});
} 展开
Long id=Long.parseLong(request.getParameter("id"));
MCountryareaVO country=new MCountryareaVO();
country.setCaId(id);
List<MProvinceVO> provinceList=provinceService.queryProvinceNames(country);
JSONObject obj=new JSONObject();
obj.put("provinceList", provinceList);
response.getWriter().write(obj.toString());
return null;
}
function doBaseCountry(){
var id=$("#country").attr("value");
$.getJSON("<c:url value='/baseInfo/airlinesAction_doQueryProvince.do'/>?id="+id,null,function(data){
for(var i=0;i<data.provinceList.length;i++){
alert(data.provinceList[i].name);
}
});
} 展开
展开全部
你先 alert(data)。看看有没有数据.
然后直接 alert(data[i]点属性);
这样应该没有问题的.
然后直接 alert(data[i]点属性);
这样应该没有问题的.
追问
alert(data)。 有数据 alert(data.provinceList[i]) 可以拿到对象 alert(data[i]点属性); 直接出错? 我认为alert(data.provinceList[i]) 他本身还是个字符串? 所以点属性的时候弹出未定义
追答
呵呵,getJson() 我不太清楚,贴段代码给你参考吧.
后台servlet里面的代码:List list=new ArrayList();
list.add(user1);
list.add(user2);
JSONArray ja=JSONArray.fromObject(list);
out.print(ja);
out.flush();
out.close();
前台: $.ajax({
data:'',
url:url,
type:'post',
dataType:'json',
success: function(data){
alert(data[0].uname); },
error:function(data){
alert('错误');
}
});
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询