Tuesday, 13 August 2013

Escaping the whole object array with JQuery

Escaping the whole object array with JQuery

Can I escape array of object with Jquery ? I got error SyntaxError:
illegal character when I retrieving Java.Util.List object. At my
Controller class , I pass object array as like that..
Map<String, List<User>> result = new HashMap<String, List<User>>();
// getting datas from database
List<User> datas = new ArrayList<User>();
datas = dao.get...................
result.put("data",datas);
When I gettting it from my JSP as
<script type="text/javascript">var results = ${result.data};</script>
I got syntaxError.So, I googling it and I assume my object array contains
illegal characters and I should escape them. (This may my opinion ). So ,
I tried to escape charaters of this object array but I don't know how to
do it ? I tried as like these..
console.log(JSON.stringify()${result.data}));
console.log(${result.data}.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&'));
console.log(${result.data}.replace(/[\u0021-\u002f\u003a-\u0040\u005b-\u005e\u0060\u007b-\u007e]/g,
""));
console.log($.grep( ${result.data}, function(e){ return e.id == id; }));
Now I am still trouble in it . Any suggestion would be appreciated. My
main point to get is I want to use my object array without any
error.Please help me.

No comments:

Post a Comment