日期:2014-05-16 浏览次数:20342 次
http://www.json.org/js.html
To convert a JSON text into an object, you can use the eval() function. eval() invokes the JavaScript compiler. Since JSON is a proper subset of JavaScript, the compiler will correctly parse the text and produce an object structure. The text must be wrapped in parens to avoid tripping on an ambiguity in JavaScript's syntax.
var myObject = eval('(' + myJSONtext + ')');
举例:
???? var str = '{host:"localhost",sourceDir:"d:\\temp"}';
??? var jsonstr = eval('('+str+')');
??? alert(jsonstr.host);//localhost