如何在React Native上从本地JSON文件获取数据? [英] How to fetch data from local JSON file on react native?

查看:641
本文介绍了如何在React Native上从本地JSON文件获取数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何存储本地文件(例如JSON),然后从控制器中获取数据?

How can I store local files such as JSON and then fetch the data from controller?

推荐答案

自从React Native 0.4.3起,您可以像这样读取本地JSON文件:

Since React Native 0.4.3 you can read your local JSON file like this:

const customData = require('./customData.json');

,然后像普通的JS对象一样访问customData.

and then access customData like a normal JS object.

这篇关于如何在React Native上从本地JSON文件获取数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆