深入研究以访问对象数组中的子对象

时间:2019-12-12 06:07:38

标签: javascript json

我正在从HTTP服务获取数据,并且应该将其保存到内部数据库中,但是我可以正确地执行此操作,但是我现在面临的问题是我无法把握某些条件部分数据从名为weekDays的服务返回,该数据是星期几

API的JSON

{
  "activeUsers": [

    {
      "id": 1,
      "status": "ACTIVE",
      "primary": false,
      "fullName": "John Doe",
      "gender": "MALE",
      "primaryContact": "+0011234567",
      "customizations": [
        {
          "id": 17,
          "isEnabled": true,
          "userType": "admin",
          "schedule": {
            "endDate": "2019-12-09",
            "weekDays": [0:2,1:5],
            "customWeekDays": [],
            "startDate": "2019-12-13",
            "frequency": "Once"
          },
          "pDate": null
        }
      ]
    }
  ]
}

将json映射到数据库

this.realm.write(() => {

          Object.keys(data_array).map((key) => {
            new_delegate = {
                id: data_array[key].id,
                full_name: data_array[key].fullName,
                gender: data_array[key].gender,
                primary_contact: data_array[key].primaryContact,
                frequency: data_array[key].customizations[key].others.frequency,
                weekdays: data_array[key].customizations[key].others.weekDays[key]
              }
              this.realm.create('users', new_users, true)
            })
          })

任何人都可以帮助我找到如何将weekDays数组从服务插入数据库的解决方案吗?

0 个答案:

没有答案