我正在使用以下库将XML转换为JSON:https://github.com/Leonidas-from-XIV/node-xml2js。转换后,控制台记录如下:
{ '@':
{ RaceDayDate: '2012-03-15T00:00:00',
Year: '2012',
Month: '3',
Day: '15',
DayOfTheWeek: 'Thursday',
MonthLong: 'March',
IsCurrentDay: '1',
IsPresaleMeeting: '0',
ServerTime: '2012-03-15T19:48:47.840' },
PresaleRaceDate: [ { '@': [Object] }, { '@': [Object] }, { '@': [Object] } ],
Meeting:
[ { '@': [Object], Pool: [Object], Race: [Object] },
{ '@': [Object], Pool: [Object], Race: [Object] },
{ '@': [Object], Pool: [Object], Race: [Object] },
@符号代表着JavaScript中一个特殊的属性,叫做“computed property names” 。如果要访问result对象中的RaceDayDate、Year、Month属性,应该使用result['RaceDayDate']、result['Year']、result['Month']等语法,而不是result.@。