<i id='qCCUs'><tr id='qCCUs'><dt id='qCCUs'><q id='qCCUs'><span id='qCCUs'><b id='qCCUs'><form id='qCCUs'><ins id='qCCUs'></ins><ul id='qCCUs'></ul><sub id='qCCUs'></sub></form><legend id='qCCUs'></legend><bdo id='qCCUs'><pre id='qCCUs'><center id='qCCUs'></center></pre></bdo></b><th id='qCCUs'></th></span></q></dt></tr></i><div id='qCCUs'><tfoot id='qCCUs'></tfoot><dl id='qCCUs'><fieldset id='qCCUs'></fieldset></dl></div>

    <small id='qCCUs'></small><noframes id='qCCUs'>

    <tfoot id='qCCUs'></tfoot>

        <bdo id='qCCUs'></bdo><ul id='qCCUs'></ul>
    1. <legend id='qCCUs'><style id='qCCUs'><dir id='qCCUs'><q id='qCCUs'></q></dir></style></legend>
      1. 在 JavaScript 中使用两种方式散列 JSON 字符串以用于 URL

        Two way hashing JSON String in JavaScript for use in URL(在 JavaScript 中使用两种方式散列 JSON 字符串以用于 URL)

            • <bdo id='AHFZO'></bdo><ul id='AHFZO'></ul>

              <tfoot id='AHFZO'></tfoot>

              <small id='AHFZO'></small><noframes id='AHFZO'>

                <tbody id='AHFZO'></tbody>

              1. <i id='AHFZO'><tr id='AHFZO'><dt id='AHFZO'><q id='AHFZO'><span id='AHFZO'><b id='AHFZO'><form id='AHFZO'><ins id='AHFZO'></ins><ul id='AHFZO'></ul><sub id='AHFZO'></sub></form><legend id='AHFZO'></legend><bdo id='AHFZO'><pre id='AHFZO'><center id='AHFZO'></center></pre></bdo></b><th id='AHFZO'></th></span></q></dt></tr></i><div id='AHFZO'><tfoot id='AHFZO'></tfoot><dl id='AHFZO'><fieldset id='AHFZO'></fieldset></dl></div>
              2. <legend id='AHFZO'><style id='AHFZO'><dir id='AHFZO'><q id='AHFZO'></q></dir></style></legend>
                • 本文介绍了在 JavaScript 中使用两种方式散列 JSON 字符串以用于 URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我想获取一个 JSON 字符串并对其进行加密/散列/编码,以便将其放入 URL 中,使其类似于如下所示的内容:

                  I would like to take a JSON string and encrypt/hash/encode it so that I can put it into a URL so that it would resemble something such as seen below:

                  var stringToEncode = JSON.stringify({foo: 'baz', bar: [1,2,3,4,5], baz: {fizzle: 'buzz'}});
                  

                  'www.myrandomurl.com/someurl/123fas234asf1543rasfsafda'

                  然后我想获取该加密/散列/编码字符串,并将其解码回其原始 JSON 字符串,以便我可以使用它来绑定到单页 AngularJS 应用程序上的各种元素.

                  I would then like to take that encrypted/hashed/encoded string, and decode it back to its original JSON string so that I can use it to bind to various elements on a single-page AngularJS application.

                  JSON 字符串的内容不敏感,因此不需要安全性或复杂的散列.唯一的条件是它必须是一个URL/URI 'safe'"字符串,为了虚荣目的而进行哈希处理,如上所示.

                  The contents of the JSON string are not sensitive so security or complex hashing is not required. The only condition is that It needs to be a "URL/URI 'safe'" string that is hashed for vanity purposes like seen above.

                  我对加密/编码的了解有限,但是我考虑过简单地将字符串编码为 Base64 并再次解码.

                  I am limited in knowledge of encrypting/encoding however I have thought about simply encoding the string to Base64 and decoding it again.

                  这是最好的方法吗?如果没有,有什么更好的方法?

                  Is this the best approach? What is a better method if not?

                  推荐答案

                  使用 encodeURIComponent() 为 url 编码

                  Use encodeURIComponent() to encode it for the url

                  要解码,请使用 decodeURIComponent()函数

                  To decode use the decodeURIComponent() function

                  Base64 不是 URL 安全的,因为它可以包含非 url 字符,例如/+ -.(见这个问题)

                  Base64 is not URL safe since it can contain non url characters like / + -. (See this question)

                  如果您希望您的 url 与原始字符串不太相似,您可以先转换为 base64,然后通过从 base 64 解码和 covrrtibg 进行编码和反转

                  If you want your url to not be too similair to the original string you can first covert to base64 and then encode and reverse by decoding and covrrtibg back from base 64

                  // to url
                  encodeURIComponent(btoa(str))
                  
                  // from url
                  atob(decodeURIComponent(uri))
                  

                  这篇关于在 JavaScript 中使用两种方式散列 JSON 字符串以用于 URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  ajax请求获取json数据并处理的实例代码 $.ajax({ type: 'GET', url: 'https://localhost:44369/UserInfo/EditUserJson',//请求数据 data: json,//传递数据 //dataType:'json/text',//预计服务器返回的类型 timeout: 3000,//请求超时的时间 //回调函数传参 suc
                  在开发JS过程中,会经常遇到两个小数相运算的情况,但是运算结果却与预期不同,调试一下发现计算结果竟然有那么长一串尾巴。如下图所示: 产生原因: JavaScript对小数运算会先转成二进制,运算完毕再转回十进制,过程中会有丢失,不过不是所有的小数间运算会
                  问题描述: 在javascript中引用js代码,然后导致反斜杠丢失,发现字符串中的所有\信息丢失。比如在js中引用input type=text onkeyup=value=value.replace(/[^\d]/g,) ,结果导致正则表达式中的\丢失。 问题原因: 该字符串含有\,javascript对字符串进行了转
                  Rails/Javascript: How to inject rails variables into (very) simple javascript(Rails/Javascript:如何将 rails 变量注入(非常)简单的 javascript)
                  CoffeeScript always returns in anonymous function(CoffeeScript 总是以匿名函数返回)
                  Ordinals in words javascript(javascript中的序数)

                        <tfoot id='Hroh4'></tfoot>
                          <tbody id='Hroh4'></tbody>
                      • <legend id='Hroh4'><style id='Hroh4'><dir id='Hroh4'><q id='Hroh4'></q></dir></style></legend>

                          <small id='Hroh4'></small><noframes id='Hroh4'>

                            <bdo id='Hroh4'></bdo><ul id='Hroh4'></ul>

                            <i id='Hroh4'><tr id='Hroh4'><dt id='Hroh4'><q id='Hroh4'><span id='Hroh4'><b id='Hroh4'><form id='Hroh4'><ins id='Hroh4'></ins><ul id='Hroh4'></ul><sub id='Hroh4'></sub></form><legend id='Hroh4'></legend><bdo id='Hroh4'><pre id='Hroh4'><center id='Hroh4'></center></pre></bdo></b><th id='Hroh4'></th></span></q></dt></tr></i><div id='Hroh4'><tfoot id='Hroh4'></tfoot><dl id='Hroh4'><fieldset id='Hroh4'></fieldset></dl></div>