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:
Copy codeThe Code is as follows:
// 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:
Copy codeThe Code is as follows:
// 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.
Copy codeThe Code is as follows:
// Get the JavaScript object, if JSON is used.
If (type = "json ")
Data = window ["eval"] ("(" + data + ")");
Replace it with the original 1.3.2 code.
Below are some other comments:
Jquery1.4.2 doubles the performance, but one headache is that $. the getJSON function. If the old version of JSON data is incorrectly written, JSON data cannot be obtained normally using this version.
For example:
Non-standard JSON format
Copy codeThe Code is as follows:
{Err: 1, errmsg: 'invalid ID value! Please submit from the correct table single page! '}
Earlier versions of jquery1.4.x can be obtained normally. If you use this type of format during program development, it is a headache, because if you upgrade JQUERY to the new version, this format cannot be read.
Standard JSON format. All versions can be obtained normally.
Copy codeThe Code is as follows:
{"Err": 1, "errmsg": "invalid ID value! Please submit from the correct table single page! "}
This is because native json parser is used in jquery1.4.X, which has strict requirements on the json format.
If you do not want to modify the JSON data of the program, what other methods can you use to make old data suitable for new versions?
There are some methods. You only need to restore the old version of the JSON processing function. The modification method is as follows:
Jq1.4.x Regular version Modification
Open the jquery-1.4.x.js file and find the following code:
Data = jQuery. parseJSON (data );
Modify to the following code:
Data = window ["eval"] ("(" + data + ")");
Jq1.4.x Minified version Modification
Open the jquery-1.4.x.min.js file and find the following code:
A = c. parseJSON ();
Modify to the following code:
A = window ["eval"] ("(" + a + ")");
Try your program, huh, huh, $. getJSON is normal?
Of course, if you have the ability to write regular expressions, you can modify the JSON processing regular expressions in the new parseJSON function.