在Android中使用本地json文件 [英] Using local json file in Android

查看:1653
本文介绍了在Android中使用本地json文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将使用包含一些数据的本地JSON文件。我的问题是存储文件的最佳/正确方法在哪里,我应该如何访问它及其内容?

I will be using a local JSON file with some data. My question is where is the best/proper way to store the file and how should I access it and it's contents?

我之前使用的是json,而不是本地的。

I have worked with json through http before but not a local one.

推荐答案

有很多方法,

您可以将它存储在res / raw文件夹中,并阅读与此处显示的相同内容 - https://stackoverflow.com/ a / 6349913/713778

You can store it in res/raw folder and read the same as show here - https://stackoverflow.com/a/6349913/713778

对于基本的JSON解析,Android的内置JSONObject应该可以工作 - < a href =https://developer.android.com/reference/org/json/JSONObject.html\"rel =noreferrer> https://developer.android.com/reference/org/json/JSONObject.html

For basic JSON parsing, Android's in-built JSONObject should work - https://developer.android.com/reference/org/json/JSONObject.html

对于更高级的JSON解析(json-java映射),您可以查看GSON库 - https:// code .google.com / p / google-gson /

For more advanced JSON parsing (json-java mapping), you can look at GSON library - https://code.google.com/p/google-gson/

这篇关于在Android中使用本地json文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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