forEach를 돌려서 Array로 생성해
Json 오브젝트로 만드는 방법
var result = new Array();
<c:forEach items="${infoList}" var="info">
var json = new Object();
json.loginId = '${info.LOGIN_ID}';
json.loginAuth = '${info.LOGIN_AUTH}';
result.push(json);
</c:forEach>
console.log($.parseJSON(JSON.stringify(result)));
//------------------------------------------------------------------------------------------------------------
추가 함수로 Replace로 변경해서 사용하는 방법
// map 형식인경우
// {MsgIdx=87,RegUser=test,RegDate=20170320135814,ModUser=test,ModDate=20170320185047}
var price= '${listResult.orderList}';
price = '{list='+price+'}';
_price = JSON.parse(getStringify(price));
// 다중리스트 인 경우 (List 안에 Map 안에 List)
/*[{ModDate=20170320185047, MsgIdx=87, RegDate=20170320135814, priceList=[{MsgIdx=1915,MealCode=222,MealPrice=8000},{MsgIdx=1915,MealCode=333,MealPrice=9000}],FltNo=7C101, CfCrewNo=2},{ModDate=20170320185047, MsgIdx=87, RegDate=20170320135814, priceList=[{MsgIdx=1915,MealCode=222,MealPrice=8000},{MsgIdx=1915,MealCode=333,MealPrice=9000}],FltNo=7C101, CfCrewNo=2}]
var price= '${listResult.orderList}';
*/
price = '{list='+price+'}';
_price = JSON.parse(getStringify(price));
function getStringify(str){
str = str.replace(/{/gi, '{"');
str = str.replace(/=/gi, '":"');
str = str.replace(/, /gi, '","');
str = str.replace(/}/gi, '"}');
str = str.replace(/}","{/gi, '},{');
str = str.replace(/":"\[/gi, '":\[');
str = str.replace(/\]","/gi, '\],"');
str = str.replace(/"}\]"}/gi, '"}\]}');
return str;
}
'Developers' 카테고리의 다른 글
JSTL 날짜 비교 (5일간 new 아이콘) (0) | 2017.05.01 |
---|---|
jsp 간단 엑셀 다운로드 (2) | 2017.03.23 |
스프링 관련 홈페이지 (0) | 2017.03.14 |
Json Search (0) | 2017.02.17 |
스프링 jsonView 설정 (0) | 2017.01.24 |
댓글