【问题标题】:get detail json in react在反应中获取详细的json
【发布时间】:2026-02-22 01:15:02
【问题描述】:
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) 输出 = 未定义 但是 console.log(dataItem) 输出已满 来自 console.log(dataItem) 的控制台输出下方的照片

【问题讨论】:

    标签: json reactjs


    【解决方案1】:

    我认为您的“dataItem”对象有问题。你能评论“dataItem”的 JSON 输出吗?

    【讨论】:

    • 嗨,Afzal 我提出了“dataItem”的输出