spring mvc ajax json,java - spring mvc ajax json malformed sometimes - Stack Overflow

libraries used

spring.4.3.4 jar

jquery 1.9.1

gson-2.2.2 jar

Using JDBCTemplate

Controller

@RequestMapping(value = "user/getApmcBudgTransData", method = RequestMethod.POST, produces = "application/json; charset=UTF-8")

public @ResponseBody String getUserLevelMasterDetails(HttpServletRequest request,HttpServletResponse res) {

ModelAndView model = new ModelAndView();

String yrmstid=request.getParameter("finyrMstid");

String apmcid=request.getParameter("apmcid");

String sendToOfc = request.getParameter("sendToOfc");

String opFlag = request.getParameter("opFlag");

String formType = request.getParameter("formType");

ArrayList apmcBudgtrandata=budgetService.getApmcBudgTransData(apmcid, yrmstid, sendToOfc, opFlag, formType);

Gson gson = new Gson();

return gson.toJson(apmcBudgtrandata);

}

JSP ajax call

$.ajax({

url:"${pageContext.request.contextPath}/user/getApmcBudgTransData",

type:'post',

dataType: 'json',

async:false,

data: {

finyrMstid :lastyr,

apmcid : pkvalue,

sendToOfc : "APMC",

opFlag : flag,

formType : "S"

},

success: function(resp) {},

error: function(err) {}

});

spring-servlet.xml

xmlns:context="http://www.springframework.org/schema/context"

xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xmlns:util="http://www.springframework.org/schema/util"

xsi:schemaLocation="

http://www.springframework.org/schema/beans

http://www.springframework.org/schema/beans/spring-beans-3.0.xsd

http://www.springframework.org/schema/context

http://www.springframework.org/schema/context/spring-context-3.0.xsd

http://www.springframework.org/schema/mvc

http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd

http://www.springframework.org/schema/util

http://www.springframework.org/schema/util/spring-util-2.5.xsd">

class="org.springframework.web.servlet.mvc.WebContentInterceptor">

class="org.springframework.web.servlet.view.InternalResourceViewResolver">

The ajax call is receiving a large amout of utf-8 json data from controller.

The json is wellformed in the controller each and every time.

When the control is returned back to ajax call, the first time, the json is malformed and error function is called.

The second and each subsequent time though, the json is wellformed and success function is called.

Firebug screenshot

Malformed json

[

{

"finYrID": "3",

"budgetTransId": "18127210",

"operationId": "",

"commonTrno": "165",

"suppliBudgYn": "N",

"tranDate": "10/05/2016",

"srNo": "1",

"apmcGlMstId": "1",

"apmcMstId": "165",

"lastYrActualAmt": "2741406",

"currYrActualAmt": "2562",

"currYrExpAmt": "0",

"currYrTotExpAmt": "2562",

"apmcCurrBudgAmt": "2379",

"disCurrBudgAmt": "2379",

"divCurrBudgAmt": "2379",

"apmcRemark": "",

"distRemark": "",

"divRemark": "",

"msambRemark": "शिफारस आहे",

"sanctionRemark": "",

"suppBudAmt": "0",

"suppDistBudgAmount": "",

"suppDivBudgAmount": "",

"suppHoBudgetAmt": "",

"suppBudgetRemark": "",

"suppDisRemark": "",

"suppDivRemark": "",

"suppHoRemark": "",

"suppSancRemark": "",

"printPosition": "",

"forwardStatus": "P",

"lastYrBudgamt": "3035810",

"msambCurYrBudgAmt": "2379",

"glName": "सुरवातीची रोख शिल्लक ",

"abrxFlg": "INCOME",

"parentId": "",

"allowEntry": "Y",

"apmcTranDate": "12/05/2016",

"distTranDate": "24/05/2016",

"divTranDate": "06/06/2016",

"hoTranDate": "19/07/2016",

"sanctionDate": "20/09/2016",

"docAppFlag": "",

"suppBudgTrno": "100165",

"apmcSuppTranDate": "",

"distSuppTranDate": "",

"divSuppTranDate": "",

"hoSuppTranDate": "",

"sancSuppDate": "",

"suppDocAppFlag": "Y",

"budgSendToOffice": "SANCTION",

"suppSendToOffice": "APMC",

"suppCurYrActualAmt": "2379",

"suppCurYrExpectedAmt": "0",

"suppCurYrTotExpectedAmt": "2379"

},

{

"finYrID": "3",

"budgetTransId": "18127209",

"operationId": "",

"commonTrno": "165",

"suppliBudgYn": "N",

"tranDate": "10/05/2016",

"srNo": "181",

"apmcGlMstId": "181",

"apmcMstId": "165",

"lastYrActualAmt": "0",

"currYrActualAmt": "0",

"currYrExpAmt": "304852",

"currYrTotExpAmt": "304852",

"apmcCurrBudgAmt": "438307",

"disCurrBudgAmt": "1238307",

"divCurrBudgAmt": "1148307",

"apmcRemark": "",

"distRemark": "898751.00",

"divRemark": "",

"msambRemark": "",

"sanctionRemark": "",

"suppBudAmt": "315514",

"suppDistBudgAmount": "0",

"suppDivBudgAmount": "0",

"suppHoBudgetAmt": "0",

"suppBudgetRemark": "",

"suppDisRemark": "",

"suppDivRemark": "",

"suppHoRemark": "",

"suppSancRemark": "",

"printPosition": "",

"forwardStatus": "P",

"lastYrBudgamt": "0",

"msambCurYrBudgAmt": "898751",

"glName": "अखेरची बँक शिल्लक ",

"abrxFlg": "EXPENSES",

"parentId": "",

"allowEntry": "Y",

"apmcTranDate": "12/05/2016",

"distTranDate": "24/05/2016",

"divTranDate": "06/06/2016",

"hoTranDate": "19/07/2016",

"sanctionDate": "20/09/2016",

"docAppFlag": "",

"suppBudgTrno": "100165",

"apmcSuppTranDate": "",

"distSuppTranDate": "",

"divSuppTranDate": "",

"hoSuppTranDate": "",

"sancSuppDate": "",

"suppDocAppFlag": "Y",

"budgSendToOffice": "SANCTION",

"suppSendToOffice": "APMC",

"suppCurYrActualAmt": "957593",

"suppCurYrExpectedAmt": "",

"suppCurYrTotExpectedAmt": "957593"

}

]

I cannot for the love of programming figure out why this is happening.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值