Article category: Web Front-end
The original code written with jquery1.3.2 is replaced with 1.4.2, And the JSON file loaded with jquery. Ajax () cannot be loaded normally. (The same applies to jquery. getjson)
The content of the original JSON file is:
{
Label: 'Europe (EU27 )',
Data: [[1999, 3.0], [2000, 3.9], [2001, 2.0], [2002, 1.2], [2003, 1.3], [2005, 2.0], [2006, 3.1], [2007, 2.9], [2008, 0.9]
}
Solution 1:
To be changed to the standard JSON format, you must use "" For all strings. The modified content is as follows:
{
"Label": "Europe (EU27 )",
"Data": [[1999, 3.0], [2000, 3.9], [2001, 2.0], [2002, 1.2], [2003, 1.3, 2.5], [2005, 2.0], [2006, 3.1], [2007, 2.9], [2008, 0.9]
}
In this way, it can be loaded normally.
Solution 2:
Find "parsejson: function" in the jQuery-1.4.2.js and you can find the following code:
JS Code
- // Logic borrowed from http://json.org/json2.js
- If (/^ [\], :{}\ S] * $/. Test (data. Replace (/\\(? : ["\\\/Bfnrt] | U [0-9a-fa-f] {4})/g ,"@")
- . Replace (/"[^" \ n \ r] * "| true | false | null | -? \ D + (? : \. \ D *)? (? : [EE] [+ \-]? \ D + )? /G, "]")
- . Replace (/(? : ^ |: | ,)(? : \ S * \ [) +/g ,""))){
- // Try to use the native JSON parser first
- Return window. JSON & window. JSON. parse?
- Window. JSON. parse (data ):
- (New function ("return" + Data ))();
- } Else {
- Jquery. Error ("invalid JSON:" + data );
- }
The parsejson function is used in httpdata: function:
JS Code
- // Get the JavaScript Object, if JSON is used.
- If (type = "JSON" |! Type & CT. indexof ("JSON")> = 0 ){
- Data = jquery. parsejson (data );
In jquery1.3.2, the following code is directly used instead of parsejson.
JS Code
- // Get the JavaScript Object, if JSON is used.
- If (type = "JSON ")
- Data = Window ["eval"] ("(" + Data + ")");
Replace it with the original 1.3.2 code.