【问题标题】:How do I read a single object from json file in react?如何在反应中从 json 文件中读取单个对象?
【发布时间】:2021-01-06 20:52:56
【问题描述】:

我想返回单个json对象并读取ip地址

//This is the object in json file
{"ip":"http://localhost:8080"}

例如,我想要

import urlAddress from './url.json';

const url = //the json value;
console.log(url);

【问题讨论】:

标签: json reactjs


【解决方案1】:

objects.json

export default {
  "ip":"127.0.0.1"
}

app.js

import objects from './objects'
console.log(objects.ip) // output: 127.0.0.1

【讨论】:

  • 谢谢您的快速回复
猜你喜欢
  • 2019-09-20
  • 2020-12-25
  • 1970-01-01
  • 2019-11-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多