Accessing Json fields with weird characters

后端 未结 3 2027
醉话见心
醉话见心 2020-12-17 03:24

i have a json string im converting to object with a simple eval(string);

heres the sample of the json string:
var json = @\'
\"{ description\" : { \"#cdata-s         


        
3条回答
  •  没有蜡笔的小新
    2020-12-17 03:55

    While the official spec for JSON specifies simply for chars to be provided as a field identifier, when you parse your JSON into a Javascript object, you now fall under the restrictions of a Javascript identifier.

    In the Javascript spec, an identifier can start with either a letter, underscore or $. Subsequent chars may be any letter, digit, underscore or $.

    So basically, the # is valid under the JSON spec but not under Javascript.

提交回复
热议问题