日期:2014-05-16 浏览次数:20378 次
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <script type="text/javascript" src="lib/jquery/jquery-1.4.2.js"></script> <!--<script type="text/javascript" src="lib/jquery/json_parse.js"></script>--> <script type="text/javascript" src="lib/jquery/json2.js"></script> <title>toJSON方法研究参考http://www.popo4j.com/article/Javscript-parsing-JSON.html</title> <script type='text/javascript'> $(function(){ }) </script> <script type="text/javascript"> </script> <script> var jsonstring = '{"name":"axis", "org":"ph4nt0m", "blog":"http://hi.baidu.com/aullik5"}'; //格式上是有要求的http://www.cnblogs.com/kenn/archive/2010/07/08/1773470.html //var ok = json_parse(jsonstring); // 在ie里必须引入包json_parse.js var ok=JSON.parse(jsonstring);// 浏览器内置的API alert(ok.blog); </script> <script type="text/javascript"> var t="{'firstName': 'cyra', 'lastName': 'richardson', 'address': { 'streetAddress': '1 Microsoft way', 'city': 'Redmond', 'state': 'WA', 'postalCode': 98052 },'phoneNumbers': [ '425-777-7777','206-777-7777' ] }"; //这种表示方法是错误的 var t = '{"firstName": "cyra", "lastName": "richardson", "address": { "streetAddress": "1 Microsoft way", "city": "Redmond", "state": "WA", "postalCode": 98052 },"phoneNumbers": [ "425-777-7777","206-777-7777" ] }'; //var obj=json_parse(t); var obj=JSON.parse(t); alert(obj.firstName); alert(obj.lastName); </script> </head> <body> 有两个类库可以使用,一个是json2.js,另一个是json_parse.js 参考文献有http://www.popo4j.com/article/Javscript-parsing-JSON.html http://blog.csdn.net/loseone/archive/2009/05/20/4203300.aspx http://www.cnblogs.com/kenn/archive/2010/07/08/1773470.html </body> </html>