IE parseerror with JSON&jQuery
来源:互联网 发布:淘宝要几天退货才算 编辑:程序博客网 时间:2024/06/08 03:19
Recently my project has a page which will load amount of data, as this project use jQuery heavily even use it in wrong way, say return data from DB and then java layer only wraps it to Object, with JBoss Resteasy, this Object is transferred to javascript layer as JSON type.
After this, big challenge comes to Browser, JS would iterate this complex Object to get demanded data, this process involves loop, filtering and sorting, even second level loop for filter duplicated data. The time to this process is as long as IE Browser complaints with
Error message: "A script on this page is causing Internet Explorer to run slowly"
Under this circumstance, we would like to withdraw data handling work from JS to Java, we define below java data structure:
public class TurbineAuxiliary {private List<Customer> customers = new ArrayList<TurbineAuxiliary.Customer>(); private List<Site> sites = new ArrayList<TurbineAuxiliary.Site>();private List<Country> countries = new ArrayList<TurbineAuxiliary.Country>();private List<SiteTurbine> siteTurbines = new ArrayList<TurbineAuxiliary.SiteTurbine>();private List<UnitAttr> unitAttrs = new ArrayList<TurbineAuxiliary.UnitAttr>();private List<Technology> techs = new ArrayList<TurbineAuxiliary.Technology>();private Set<String> regions = new LinkedHashSet<String>();private Set<String> outageTypes = new LinkedHashSet<String>();private Set<String> contractRaxs = new LinkedHashSet<String>();private Set<String> csaTriggers = new LinkedHashSet<String>();
However, after JSON transform, I got below JSON data structure (even some fields are lost), it is very strange:
Anyway, if no data is lost, then corrupted data structure would not block data extracting. This data structure works fine in Chrome, but failed in IE, IE just reports
status: 200textstatus:parsererrorerrorThrown: Expected '}'
I tried to search Internet in the hope of getting some hint or solution on this, several feasible solutions for others come to me, but no luck with tries. like:
- USING JSON IN INTERNET EXPLORER WITH JQUERY
- IE8 + Jquery ajax call giving parsererror from dJango : for json data which seems valid in Firefox
My colleague change another idea, as he doubts JAXB would not recognize (or incompatible with ) Java Set, consequently the generic String cannto be parsed correctly, so he tried to use List instead of Set as well as String wrapping. The updated Java data structure is as following:
@XmlRootElementpublic class TurbineAuxiliary { private List<Customer> customers = new ArrayList<TurbineAuxiliary.Customer>(); private List<Site> sites = new ArrayList<TurbineAuxiliary.Site>(); private List<Country> countries = new ArrayList<TurbineAuxiliary.Country>(); private List<SiteTurbine> siteTurbines = new ArrayList<TurbineAuxiliary.SiteTurbine>(); private List<UnitAttr> unitAttrs = new ArrayList<TurbineAuxiliary.UnitAttr>(); private List<Technology> techs = new ArrayList<TurbineAuxiliary.Technology>(); private List<StringWrapperForJAXB> regions = new ArrayList<StringWrapperForJAXB>(); private List<StringWrapperForJAXB> outageTypes = new ArrayList<StringWrapperForJAXB>(); private List<StringWrapperForJAXB> contractRaxs = new ArrayList<StringWrapperForJAXB>(); private List<StringWrapperForJAXB> csaTriggers = new ArrayList<StringWrapperForJAXB>();
public static class StringWrapperForJAXB implements Comparable<StringWrapperForJAXB>{private String core;public StringWrapperForJAXB() {}public StringWrapperForJAXB(String core) {super();this.core = core;}@Overridepublic int compareTo(StringWrapperForJAXB o) {return this.core.compareTo(o.getCore());}public String getCore() {return core;}public void setCore(String core) {this.core = core;} }
After this change, we are getting correct JSON successfully and no data is lost, see:
From my experience, I found 2 points needs to be remarked:
- java.util.Set is not compatible with JAXB
- When use java generic, direclty use List<String> cannot be parsed correctly by JAXB, but need to have a wrapper for String.
Not have a test to verify my comments, need someone to correct me if I am wrong. This note is for future reference.
- IE parseerror with JSON&jQuery
- jquery的ajax返回json数据出现parseerror错误
- Jquery Ajax ParseError
- Jquery.ajax报parseerror Invalid JSON错误的原因和解决方法:不能解析
- Jquery.ajax报parseerror Invalid JSON错误的原因和解决方法:不能解析
- Jquery.ajax报parseerror Invalid JSON异常的原因和解决办法:不能解析
- jquery调用Web API提示"parseerror"
- ajax 从后台获取json格式 提示 parseerror
- jsForm - Html Form via JSON with jQuery
- jQuery Ajax Example With JSON Response
- 解决jQuery在ie下JSON的cache问题
- Jquery 返回json数据,IE浏览器提示下载的问题
- IE兼容性模式下 jquery处理 ajax json
- IE兼容性模式下 jquery处理 ajax json
- spring mvc 返回json数据到ajax报错parseerror问题
- MVC Techniques with jQuery, JSON, Knockout, and C#
- Play Framework 2 with Scala, Anorm, JSON, CoffeeScript, jQuery & Heroku
- javascript: Jquery each loop with json array or object
- 【diannaoxitong】Linux不为人知的12大内幕
- 双轴测试转台
- 收藏
- 你应该更新的Java知识之Optional
- JS的跨页面请求
- IE parseerror with JSON&jQuery
- windows 下安装 nodejs+npm+express
- windows 下安装 npm
- struts spring 整合方式
- 如何使UIScrollView的滚动条indicator一直显示
- 基于物品的协同过滤推荐算法——读“Item-Based Collaborative Filtering Recommendation Algorithms”
- html<marquee>标签
- android:windowSoftInputMode属性使用心得
- 51 单片机UART 串口通信[ 方式1 ]实现