我该如何从json文件中读取单个对象?

时间:2020-09-20 15:43:27

标签: json reactjs

我想返回一个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);

1 个答案:

答案 0 :(得分:0)

objects.json

export default {
  "ip":"127.0.0.1"
}

app.js

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