IE parseerror with JSON&jQuery
2013-08-29 13:02
423 查看
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
Under this circumstance, we would like to withdraw data handling work from JS to Java, we define below java data structure:
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
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:
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.
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: 200 textstatus:parsererror errorThrown: 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:
@XmlRootElement 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 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; } @Override public 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.
相关文章推荐
- 教程: Play Framework 2 with Scala, Anorm, JSON, CoffeeScript, jQuery & Heroku
- ecshop Uncaught transport.js/parseResult() error: can't parse to JSON.错误
- sencha touch 通过.axhx获取后台数据时,Unable to parse the JSON returned by the server: Error: You're trying to
- How To Replace jQuery 1.9.1's $.parseJSON function with the implementation from jQuery 1.8.3
- jQuery AJAX JSON Example – jQuery.parseJSON(), $.post() & $.getJSON()
- How To Generate JSON With PHP and Parse It With JQuery
- json格式字符串用jquery.parseJSON()出现的问题 Uncaught SyntaxError: Unexpected token ' Uncaught SyntaxError: Une
- Play Framework 2 with Scala, Anorm, JSON, CoffeeScript, jQuery & Heroku
- velocity.exception.ParseErrorException: Encountered "<EOF>"
- Android studio中的一次编译报错’Error:Execution failed for task ':app:transformClassesWithDexForDebug‘,困扰了两天
- ERROR ITMS-9000: "Redundant Binary Upload. There already exists a binary upload with build version '
- org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContex
- Error on line 24 of document : Open quote is expected for attribute "{1}" associated with an eleme
- js SyntaxError: JSON.parse: bad control character
- error: command 'gcc' failed with exit status 1
- Error creating bean with name 'sessionFactory' defined in ServletContext resource
- Error creating bean with name 'dwrSysuserDao' defined in ServletContext resource
- Putty connects Ubuntu12.04 in Virtualbox with error &quot;network error software caused connection abort&quot;
- Hierarchical Treeview with ASP.NET MVC & jQuery
- MVC Techniques with jQuery, JSON, Knockout, and C#