jquery ajax parseerror问题

以前都是用ajax做一些简单的东东,很少用ajax做查询。今日在开发中遇到个比较基础但是却很容易犯的错误,可能会使新手束手无策,于是写此blog分享心得
好了话不多说直接步入正题贴上代码
jquery请求代码:

$("#show_supply_table").click(function() {
var datas={time:time,event:event,supply:supply,productName:productName};
var paths=path+"/statistic/aboutSupply.shtml";
$.ajax({
type:"get",
url:paths,
dataType:"json",
data:datas,
success:function(data){
alert("对鸟!!");
},error:function(a,b){
alert(b);
}
});

});

但是重点不在jquery里,再看java代码 注:我这里是使用的spring的Controller,这里重点不在框架,而是在返回的结果,使用任何框架都是一样的.因为你返回的东西都是一样
/**
* 处理ajax请求,返回查询结果
*
* @author Quinn He
* @param time 时间范围
* @param event 事件
* @param supply 供应商
* @param productName 产品名
* @dateTime 2012-3-2 下午2:19:01
* @param request
* @param response
* @return java.util.Map<String, Object>
*/
@RequestMapping(value = "/statistic/aboutSupply.shtml", method = RequestMethod.GET)
@ResponseBody
protected Map<String, Object> aboutSupply(@RequestParam(value = "time") String time,
@RequestParam(value = "event") String event, @RequestParam(value = "supply") String supply,
@RequestParam(value = "productName") String productName, final HttpServletRequest request,
final HttpServletResponse response) {
Map<String, Object> model = new HashMap<String, Object>();
time = StringUtils.isEmpty(time) ? null : time;
event = StringUtils.isEmpty(event) ? null : event;
supply = StringUtils.isEmpty(supply) ? null : supply;
productName = StringUtils.isEmpty(productName) ? null : productName;
String[] params = { time, event, supply, productName };
List<ApkStatisticRawBean> list = this.querySupplyDetail(params, null);
model.put("aboutSupplys", list);
return model;
}

通过这段代码可以看到本人返回了一个List对象,看似毫无问题的代码,可是它偏偏就出了问题...jquery里始终是执行的
error:function(a,b){
alert(b);
}
[img]http://dl.iteye.com/upload/attachment/0064/1015/9bc94f1c-2c63-3752-af64-6a6598f58aff.jpg[/img]
于是我疑惑的打开了firefox,通过firefox我发现请求响应200了
[img]http://dl.iteye.com/upload/attachment/0064/1017/c385467b-17ba-3f0e-b874-5f8f171ff4bd.jpg[/img]
图片上的内容就是返回的是将LIST转换为JSON集合后的结果,先别管其它,至少知道了数据已经返回回来了.返回回来了为什么还error了呢?并且还提示parseerror错误?
问题就在最后一部转换的时候,LIST转换为JSON的时候
看看ApkStatisticRawBean里面究竟是什么东东
import java.util.ArrayList;
import java.util.Date;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import me.gall.business.model.mybatis.bean.ApkStatisticRaw;
import me.gall.business.model.mybatis.bean.SupplyInfo;
import me.gall.business.service.init.SystemServiceImpl;

/**
* @author Quinn He
* @dateTime 2012-2-9 下午4:35:18
*/
public class ApkStatisticRawBean {

/**
* @author Quinn He
* @dateTime 2012-2-29 下午6:06:24
* @param bean
*/
public ApkStatisticRawBean(ApkStatisticRaw bean) {
this.id = bean.getId();
this.uuid = bean.getUuid();
if (bean.getApkId() != null) {
this.apk = SystemServiceImpl.getInstance().getBaseApkMap().get(bean.getApkId());
}
if (bean.getChannelId() != null) {
this.channel = SystemServiceImpl.getInstance().getChannels().get(bean.getChannelId());
}
if (bean.getSupplyId() != null) {
this.supply = SystemServiceImpl.getInstance().getSupplys().get(bean.getSupplyId()).getSupply();
}
this.content = bean.getContent();
if (bean.getCreateTime() != null) {
this.createTime = new Date(bean.getCreateTime());
}
this.creator = bean.getCreator();
if (bean.getEventId() != null) {
this.event = SystemServiceImpl.getInstance().getApkStatisticCategoryEventMap().get(bean.getEventId());
}
this.numbers = bean.getNumbers();
this.other = bean.getOther();
this.productName = bean.getProductName();
this.status = bean.getStatus();
if (bean.getTime() != null) {
this.time = new Date(bean.getTime());
}
}




/**
* This field was generated by MyBatis Generator. This field corresponds to the database column apk_statistic_raw.id
*
* @mbggenerated Thu Feb 09 17:04:23 CST 2012
*/
private Integer id;

/**
* This field was generated by MyBatis Generator. This field corresponds to the database column apk_statistic_raw.uuid
*
* @mbggenerated Thu Feb 09 17:04:23 CST 2012
*/
private String uuid;

/**
* This field was generated by MyBatis Generator. This field corresponds to the database column apk_statistic_raw.apk_id
*
* @mbggenerated Thu Feb 09 17:04:23 CST 2012
*/
private ApkBean apk;

/**
* This field was generated by MyBatis Generator. This field corresponds to the database column apk_statistic_raw.event_id
*
* @mbggenerated Thu Feb 09 17:04:23 CST 2012
*/
private ApkStatisticCategoryEventBean event;

/**
* This field was generated by MyBatis Generator. This field corresponds to the database column apk_statistic_raw.supply_id
*
* @mbggenerated Thu Feb 09 17:04:23 CST 2012
*/
private SupplyInfo supply;

/**
* This field was generated by MyBatis Generator. This field corresponds to the database column apk_statistic_raw.channel_id
*
* @mbggenerated Thu Feb 09 17:04:23 CST 2012
*/
private ChannelBean channel;

/**
* This field was generated by MyBatis Generator. This field corresponds to the database column
* apk_statistic_raw.product_name
*
* @mbggenerated Thu Feb 09 17:04:23 CST 2012
*/
private String productName;

/**
* This field was generated by MyBatis Generator. This field corresponds to the database column apk_statistic_raw.content
*
* @mbggenerated Thu Feb 09 17:04:23 CST 2012
*/
private String content;

/**
* This field was generated by MyBatis Generator. This field corresponds to the database column apk_statistic_raw.time
*
* @mbggenerated Thu Feb 09 17:04:23 CST 2012
*/
private Date time;

/**
* This field was generated by MyBatis Generator. This field corresponds to the database column apk_statistic_raw.numbers
*
* @mbggenerated Thu Feb 09 17:04:23 CST 2012
*/
private Integer numbers;

/**
* This field was generated by MyBatis Generator. This field corresponds to the database column apk_statistic_raw.status
*
* @mbggenerated Thu Feb 09 17:04:23 CST 2012
*/
private Integer status;

/**
* This field was generated by MyBatis Generator. This field corresponds to the database column apk_statistic_raw.creator
*
* @mbggenerated Thu Feb 09 17:04:23 CST 2012
*/
private String creator;

/**
* This field was generated by MyBatis Generator. This field corresponds to the database column apk_statistic_raw.create_time
*
* @mbggenerated Thu Feb 09 17:04:23 CST 2012
*/
private Date createTime;

/**
* This field was generated by MyBatis Generator. This field corresponds to the database column apk_statistic_raw.other
*
* @mbggenerated Thu Feb 09 17:04:23 CST 2012
*/
private String other;
get.....
set.....

原来是我在此对象里面封装了对象
	private ApkBean apk;

/**
* @author Quinn He
* @dateTime 2011-11-15 下午2:20:27
*/
public class ApkBean {
...
private JarBean jar;
...
}


public class JarBean {
...
private List<ApkBean> apkList;
...
}
问题就出在这里了...我的ApkBean里面有JarBean JarBean中有List<ApkBean>
在将List转为JSON的时候会解析到ApkBean然后里面有JarBean又开始解析JarBean然后JarBean里面又有List<APkBean> 然后又开始解析ApkBean了....
死循环了...!!!
说到这里 相比不明白的差不多也明白了吧...如果你的POJO里面有太多的关联最好不要直接返回..而是针对要返回的需求再创建一个POJO内容自己填充 我这里就是这样解决的
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值