How to prevent removing decimal point when parsing JSON?

后端 未结 4 1402
灰色年华
灰色年华 2020-12-11 16:36

If you do this...

var parsed = JSON.parse(\'{\"myNum\":0.0}\') ;

Then when you look at parsed.myNum, you just get 0

4条回答
  •  执笔经年
    2020-12-11 17:12

    If 0.0 is not enclosed in quotes in your JSON (i.e. it's a number and not a string), then there's no way to distinguish it from 0, unless you write your own JSON parser.

提交回复
热议问题