What is the difference between a JS object literal and a JSON string?

后端 未结 6 1716
灰色年华
灰色年华 2021-02-04 19:47

I have confusion about what exactly people mean by Object Literals, JSON, JavaScript Objects, to me they seem similar:

{foo: \'bar\', bar : \'baz\'}
6条回答
  •  死守一世寂寞
    2021-02-04 20:03

    According to the specification, in JSON all strings, whether they are values or keywords, should be surrounded by double quotes.

    Your example would be a valid JSON string if it contains the following:

    {"foo": "bar", "bar": "baz"}
    

提交回复
热议问题