JSON syntax for property names

前端 未结 4 1313
醉酒成梦
醉酒成梦 2020-11-30 07:41

What is the correct syntax to create objects in javascript that will work across the majority of web browsers (by that I mean : IE 6+, Firefox 2+, Opera 9+ )

Is this

4条回答
  •  心在旅途
    2020-11-30 08:11

    You have to use "quotes" around properties that contain anything other than word characters

    {foo-bar: 3} // invalid
    {"foo-bar": 3} // valid
    

    Other than that there is no difference between the two and I'd imagine both ways work across all browsers

提交回复
热议问题