zoukankan      html  css  js  c++  java
  • 页面跳转字符串转换为Json格式

    在做一个网站,一个页面通过地址传值到另外一个页面,接收页面得到值后需要转换为Json对象的数据。
    因为有用Jquery所以一开始用了Jquery中的一个方法

    var Info = jQuery.parseJSON(Request("Info"));

    在IE浏览器下,网页正常运行,但是在火狐浏览器,google浏览器中,会出现错误。
    只好使用JS的方法;尝试了两种方法:

    1:var Info = eval("(" + decodeURIComponent(Request("Info")) + ")");//注意需要decodeURIComponent()方法进行编码转换
    2:var Info = (new Function("", "return " + decodeURIComponent(Request("Info"))))();//用这个方法的人越来越少了,//注意也需要decodeURIComponent()方法进行编码转换

    注意:
    decodeURIComponent() 函数可对 encodeURIComponent() 函数编码的 URI 进行解码。

    <script type="text/javascript">
    
    var test1="http://www.w3school.com.cn/My first/"
    
    document.write(encodeURIComponent(test1)+ "<br />")
    document.write(decodeURIComponent(test1))
    
    </script>

    输出:

    http%3A%2F%2Fwww.w3school.com.cn%2FMy%20first%2F
    http://www.w3school.com.cn/My first/
  • 相关阅读:
    千拣万拣,拣个烂灯盏
    在JavaScript中控制链接的点击
    一条SQL语句
    Atlas与页面缓存冲突造成报错问题
    猴子他爹
    没有源代码也可以调试
    IC卡
    郭昶
    在js脚本中找到控件
    郭昶来到咱们学车场
  • 原文地址:https://www.cnblogs.com/PLifeCopyDown/p/2670122.html
Copyright © 2011-2022 走看看