Giter VIP home page Giter VIP logo

Comments (5)

Andrew-M-C avatar Andrew-M-C commented on August 25, 2024

标准的 JSON 中,object 的 key 必然是一个 string 噢
你是需求什么功能呢?

from go.jsonvalue.

Andrew-M-C avatar Andrew-M-C commented on August 25, 2024

go 表面上支持 map[int]any,但最终落地到 JSON 的时候,是转换成 string 的

from go.jsonvalue.

23fo avatar 23fo commented on August 25, 2024

我是在用本库处理一些树状结构的数据,并没有限制在json上,key有类型的话会更方便

from go.jsonvalue.

Andrew-M-C avatar Andrew-M-C commented on August 25, 2024

@kY9i
这个没办法,因为我需要解析的是一个 JSON 原始字节流,而 JSON 字节流的所有 key 都必然是一个 string,没有别的类型
即便这个 key 看起来像是一个数字,但是生成这个 key 的代码可能是把它当作 string 来处理的

举个例子,我们常见的 QQ 号,就是一个 uint64 数字,但是现在绝大部分的系统,都会将它视为一个 string 来处理。所以当你看到 {"1234567890":"这是一个QQ号"},它的 key 也是 string。JSON 不允许其他类型

此外还有一点,就是 jsonvalue 在处理参数的时候,string 和数字类型有明确的语义。string 隐含表明处理的当前的层级是一个 object,而数字则隐含表明当前处理的层级是一个 array,所以在 jsonvalue 的层面也是做不了的

这其实也带来一个问题,那么在你那边是如何区分诸如 100"100" 的呢?


不过我猜测了一下你的使用场景,我倒是想这么推荐给你:你可以把 jsonvalue 再封装一层,就是传入任何的参数类型,你都在这层胶水层中把参数转成 string 类型然后再传给 jsonvalue,这样以来,每一层都会按照 string 去处理,就像文件系统一样(我猜测这就是你想要处理的树状结构的数据)

from go.jsonvalue.

23fo avatar 23fo commented on August 25, 2024

我的数据和json类似的,只是会明确key类型,加一层的话jsonvalue里的set和get都要重新实现了。

from go.jsonvalue.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.