Java 在Android中使用本地json文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23808365/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-14 01:18:01  来源:igfitidea点击:

Using local json file in Android

javaandroideclipse

提问by user3658609

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.

我以前通过 http 使用过 json,但不是本地的。

采纳答案by ranjk89

There are so many ways,

有很多方法,

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

对于基本的 JSON 解析,Android 的内置 JSONObject 应该可以工作 - https://developer.android.com/reference/org/json/JSONObject.html

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

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