从html文档中提取json var

时间:2013-10-12 00:15:34

标签: javascript jquery html json

如何使用jquery提取这些变量的值并将它们存储到javascript var中?此标记存储在html文档的标题中

  <script type="text/javascript">
            var vip_ship_info = {
                "ship_address1":    "x",
                "ship_address2":    "x",
                "ship_country":     "x",
                "ship_postal":      "x",
                "office_title":     "x"
            };
    </script>

2 个答案:

答案 0 :(得分:1)

您的变量已经声明,只要任何引用代码放在此脚本块下面,您就可以访问内部变量:

var ship_address1 = vip_ship_info.ship_address1

使用点表示法访问对象中的值。不需要jQuery。

答案 1 :(得分:1)

vip_ship_info.ship_address1vip_ship_info["ship_address1"]