Object属性始终返回undefined

时间:2017-10-10 21:49:55

标签: javascript reactjs

我有构造函数的反应组件:

{"id":7,"email":"some@mail.ru","locale":"en","hp":100,"created_at":"2017-10-10T20:42:04.677Z","updated_at":"2017-10-10T21:35:22.297Z"}

undefined

输出:

/* clock.c */

#include "clock.h"

static volatile uint32_t clock_ticks;

uint32_t get_clock_ticks(void)
{
    return clock_ticks;
}

void clock_tick(void)
{
    clock_ticks++;
}

1 个答案:

答案 0 :(得分:1)

props.user是一个JSON字符串,而不是一个javascript对象。您需要先解析它,然后到达子属性。

constructor(props) {
    super(props);
    console.log(props.user);
    const user = JSON.parse(props.user);
    console.log(user.email);
}