Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在尝试从具有数组键的 Json 文件中获取哈希,但它返回每个数组键,如字符串。
hash = {[10, 10] => [[1, 1], [5, 5]]} p JSON.parse(hash.to_json) #=> {"[10, 10]" => [[1, 1], [5, 5]]}
也许我应该使用 YAML,知道吗?
JSON 有三个略有不同的版本,由
虽然这三者之间存在细微差别,但他们都同意一件事:对象键是字符串。总是。
换句话说,“具有数组键的 Json 文件”不可能存在。不管你有什么,它要么是一个 JSON 文件,但它不能有 Array Keys,或者它根本就不是一个 JSON 文件。