Can JSON numbers be quoted?

后端 未结 3 657
执念已碎
执念已碎 2020-11-29 07:27

Can there be quotes around JSON numbers? In most of the search links, it seems that numbers do not \"require\" quotes. But, should the parsers accept both \"attr\" : 6

3条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-11-29 07:52

    That will depend of the language that you use to get the integer, because if the programming language does not provide implicit conversion from string to int, you can have problems.

    You should not to worry too much, since modern programming language nowadays can implicitly convert a string to a number without additional code. Something you should take into consideration is, when using programming languages like JavaScript, when you use == and === when comparing values, === takes into consideration the value's type while == not, so 6 === "6" will return false, while 6 == "6" will return true.

    Answering your question, it will not throw an exception if you are using a programming language that provides implicit conversion from string to int.

提交回复
热议问题