JSON.parse: unexpected character

后端 未结 2 1300
礼貌的吻别
礼貌的吻别 2020-12-11 22:00

I\'m trying to pass a json from php jquery, after getting into an array of sql query and get the following javascript error.

JSON.parse: unexpected character         


        
2条回答
  •  春和景丽
    2020-12-11 22:29

    I just ran into this in FF10.0.2 with data that looked like:

    [ { "firstName": 'Joe', "lastName": 'Smith' } ]
    

    (with multiple objects in the array - shortened for clarity)

    It actually parsed OK using eval, though, instead of JSON.parse. (I'm not using jQuery here.)

    The problem went away when I changed ' to " for the values:

    [ { "firstName": "Joe", "lastName": "Smith" } ]
    

    I thought the " requirement was only for property names, not data values.

提交回复
热议问题