1. The old method:
CopyCode The Code is as follows: function strtojson (STR ){
VaR JSON = eval ('+ STR + ')');
Return JSON;
}
2. Common Methods:Copy codeThe Code is as follows: function strtojson (STR ){
Return (new function ("return" + Str ))();
}
3. JSON object methods not supported by ie67:Copy codeThe Code is as follows: function strtojson (STR ){
Return JSON. parse (STR );
}
4. Methods provided by jquery:Copy codeThe Code is as follows: parsejson: function (data ){
If (typeof data! = "String" |! Data ){
Return NULL;
}
Data = jquery. Trim (data );
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 ,""))){
Return window. JSON & window. JSON. parse?
Window. JSON. parse (data ):
(New function ("return" + Data ))();
} Else {
Jquery. Error ("invalid JSON:" + data );
}
},