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/
  • 相关阅读:
    pe文件结构
    dll
    术语
    创建内存映射文件
    函数的调用约定
    串口
    linux 之 tcpdump
    linux 之程序管理
    perl 之eval
    2020-10-27_组合快捷键
  • 原文地址:https://www.cnblogs.com/PLifeCopyDown/p/2670122.html
Copyright © 2011-2022 走看看