datajs = fetch(Constants.SPS_S_INVESTIGATOR_QB).then(async (response) => {
const contentType = response.headers.get('content-type');
if (contentType && contentType.indexOf('application/json') !== -1) {
const jsn = await response.json();
return jsn['DBInfoScript'].replace('var ourDB=', '');
} else {
const text = await response.text();
}
});
useEffect(() => {
if (dataItem.length == 0) {
setdataItem(datajs);
}
}, [datajs]);
console.log(dataItem);
console.log(dataItem.airtravel);
我想获取详细信息 json 但输出未定义 输出 console.log(dataItem.airtravel) output = undefin 但 console.log(dataItem) 输出已满 console.log(dataItem) 的控制台输出下方的照片
答案 0 :(得分:0)
我认为您的“dataItem”对象有问题。你能评论“dataItem”的JSON输出吗?