JSON integers: limit on size

前端 未结 3 1903
渐次进展
渐次进展 2020-11-27 16:02

Is it specified anywhere how big JSON integers can be? I\'m guessing that they\'re limited to normal (32 bit) ints, but I can\'t find anywhere that that\'s written down. I n

3条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-27 16:29

    I just did the following empirical test using Chrome (v.23 on Mac) Console:

    > var j = JSON.parse("[999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999]")
    undefined
    
    > j[0]
    1e+228
    

    If JSON is passed through HTTP then the number will be converted in String from Java in any case and then the issue could be only in Javascript.

    From ECMAScript Language Specification 4.3.19:

    4.3.19 Number value

    primitive value corresponding to a double-precision 64-bit binary format IEEE 754 value

    NOTE A Number value is a member of the Number type and is a direct representation of a number.

    Which is what defined in wikipedia Double-precision floating-point format.

提交回复
热议问题