【原创】React Native中如何解析JSON文件?
问题背景:
假定项目目录中存在如下文件系统结构: ./src/config.json,那么React Native中如何解析呢?
config.json:
{ "user":[ { "name" : "jinniuzuo", "website" : "http://www.blogdaren.com", }, { "name" : "jinniuzuo", "website" : "http://www.baodacai.com", } ] }
解决方案:
1. 导入config.json文件:
import config from './src/config.json';2. 像操作普通的模块一样操作config对象即可:
console.log('========================='); console.log(config.user[0].name); console.log(config.user[0].website); console.log('=========================');
版权声明:除非注明,本文由( blogdaren )原创,转载请保留文章出处。
发表评论: