Javascript 在React Native中使用setState存储JSON数据
我正在通过setState将JSON数据保存到构造函数变量。有什么办法吗?Javascript 在React Native中使用setState存储JSON数据,javascript,json,reactjs,react-native,Javascript,Json,Reactjs,React Native,我正在通过setState将JSON数据保存到构造函数变量。有什么办法吗? 这是我的助手: class House extends Component{ constructor(){ super(); this.state = { Lights_1: "", Windows_1: "", WantedTemp_1: "", }; } [ { "ID": 1, "name": "hall1", "light_
这是我的助手:
class House extends Component{
constructor(){
super();
this.state = {
Lights_1: "",
Windows_1: "",
WantedTemp_1: "",
};
}
[
{
"ID": 1,
"name": "hall1",
"light_state": 0,
"window_state": 0,
"wanted_temp": "20",
"actual_temp": "20"
}
]
这是我的JSON数据:
class House extends Component{
constructor(){
super();
this.state = {
Lights_1: "",
Windows_1: "",
WantedTemp_1: "",
};
}
[
{
"ID": 1,
"name": "hall1",
"light_state": 0,
"window_state": 0,
"wanted_temp": "20",
"actual_temp": "20"
}
]
如何将数据保存到VAR?
非常感谢。如果您通过axios之类的调用获取json数据,您可以将其与响应一起使用
this.setState({
id: response.ID,
window_1: response.window_state,
})
对于要设置为状态的其余项,依此类推