我在读取下面的对象项时遇到困难,直到该对象

时间:2018-08-17 13:08:59

标签: javascript node.js

我在阅读下面的对象项目时遇到困难,直到对象“ subscription”(订阅)安静运行,但我需要阅读

'subscription [current_period_end]': '2018-09-15T09: 29: 59.439Z'

任何建议怎么办?

{
  id: '912017',
  fingerprint: '6f974d687c35989377351b3cd4c4b2101da5b615',
  event: 'subscription_status_changed',
  old_status: 'unpaid',
  desired_status: 'paid',
  current_status: 'paid',
  object: 'subscription',
  'subscription[payment_method]': 'boleto',
  'subscription[card_brand]': '',
  'subscription[card_last_digits]': '',
  'subscription[current_period_start]': '2018-08-16T09:29:59.436Z',
  'subscription[current_period_end]': '2018-09-15T09:29:59.439Z',
  'subscription[charges]': '1',
  'subscription[status]': 'paid',
  'subscription[date_created]': '2018-08-15T13:41:24.888Z',
  'subscription[date_updated]': '2018-08-16T09:29:59.791Z',
  'subscription[phone]': '',
  'subscription[address]': ''
}

2 个答案:

答案 0 :(得分:1)

subscription[current_period_end]是对象的字符串键,因此您需要像这样完全传递它:

yourObj['subscription[current_period_end]']

请参阅以下演示:

var obj = {
  id: '912017',
  fingerprint: '6f974d687c35989377351b3cd4c4b2101da5b615',
  event: 'subscription_status_changed',
  old_status: 'unpaid',
  desired_status: 'paid',
  current_status: 'paid',
  object: 'subscription',
  'subscription[payment_method]': 'boleto',
  'subscription[card_brand]': '',
  'subscription[card_last_digits]': '',
  'subscription[current_period_start]': '2018-08-16T09:29:59.436Z',
  'subscription[current_period_end]': '2018-09-15T09:29:59.439Z',
  'subscription[charges]': '1',
  'subscription[status]': 'paid',
  'subscription[date_created]': '2018-08-15T13:41:24.888Z',
  'subscription[date_updated]': '2018-08-16T09:29:59.791Z',
  'subscription[phone]': '',
  'subscription[address]': ''
};

console.log(obj['subscription[current_period_end]']);

答案 1 :(得分:0)

您尝试过console.log(data["subscription[current_period_end]"])吗?