How to reliably hash JavaScript objects?

前端 未结 6 1847
天涯浪人
天涯浪人 2021-02-06 21:53

Is there a reliable way to JSON.stringify a JavaScript object that guarantees that the ceated JSON string is the same across all browsers, node.js and so on, given that the Java

6条回答
  •  走了就别回头了
    2021-02-06 22:41

    You may find bencode suitable for your needs. It's cross-platform, and the encoding is guaranteed to be the same from every implementation.

    The downside is it doesn't support nulls or booleans. But that may be okay for you if you do something like transforming e.g., bools -> 0|1 and nulls -> "null" before encoding.

提交回复
热议问题