file android closed,Reading a json file in Android [closed]
问题
I have the following json file. I want to know where should i place the json file in my project and how to read and store it.
{
\"aakash\": [
[ 0.070020,0.400684],
[ 0.134198,0.515837],
[ 0.393489,0.731809],
[ 0.281616,0.739490]
],
\"anuj\": [
[ 1287.836667,-22.104523],
[ -22.104523,308.689613],
[ 775.712801,-13.047385],
[ -13.047385,200.067743]
]
}
回答1:
Put that file in assets.
For project created in Android Studio project you need to create assets folder under the main folder.
Read that file as:
public String loadJSONFromAsset(Context context) {
String json = null;
try {
InputStream is = context.getAssets().open("file_name.json");
int size = is.available();
byte[] buffer = new byte[size];
is.read(buffer);
is.close();
json = new String(buffer, "UTF-8");
} catch (IOException ex) {
ex.printStackTrace();
return null;
}
return json;
}
and then you can simply read this string return by this function as
JSONObject obj = new JSONObject(json_return_by_the_function);
For further details regarding JSON see
http://www.vogella.com/articles/AndroidJSON/article.html
Hope you will get what you want.
回答2:
Try this:
JSONObject obj = new JSONObject(yourjsonstring);
来源:https://stackoverflow.com/questions/13814503/reading-a-json-file-in-android
file android closed,Reading a json file in Android [closed]相关推荐
- Android运行时候报错:android.view.InflateException: Binary XML file line #19: Binary XML file lin
Android运行时候报错:android.view.InflateException: Binary XML file line #19: Binary XML file lin 这个问题自己大致在 ...
- android.view.InflateException: Binary XML file line #7: Binary XML file line #7
错误如下 11-21 08:19:44.040 3608-3608/com.leon.oldrecyclerview E/AndroidRuntime: FATAL EXCEPTION: main ...
- 报错android.view.InflateException: Binary XML file line #11: Attempt to invoke virtual method 'boolean
出现这种问题,打开Android monitor的调试信息发现是 android.view.InflateException: Binary XML file line #11: Attempt to ...
- android异常 More than one file was found with OS independent path ‘META-INF/XXX‘
android异常 More than one file was found with OS independent path 'META-INF/XXX' 参考文章: (1)android异常 Mo ...
- Java – Reading a Large File Efficiently--转
原文地址:http://www.baeldung.com/java-read-lines-large-file 1. Overview This tutorial will show how to r ...
- Android studio3.0打开Device File Explore(文件管理器)的方法(图文教程)
Android studio3.0打开Device File Explore(文件管理器)的方法 看到网上AS3.0新增加的查看手机文件的新功能,全部都是转载的,没有几个人心细的把如何打开的方法写下来 ...
- android+图标+i_explore+无背景,Android Studio中Android Device Monitor中的File Explore不显示文...
环境:操作系统是Mac,模拟器 问题:Android Studio中Android Device Monitor中的File Explore不显示文件 本人在自学文件存储,想查看"dada/ ...
- python批量读取文件赋值给一个参数_求助一个Python 循环读取文件,并对读到的字符串进行赋值,然后进一步生成json file 的方法。...
求助一个Python 循环读取文件,并对读到的字符串进行赋值,然后进一步生成json file 的方法. 本来想用shell写,利用while read line do --done 但是这样json ...
- error This module isn‘t specified in a package.json file.
error This module isn't specified in a package.json file. 报错如下: 解决办法: 首先先删除node_modules安装包,执行以下命令 (没 ...
最新文章
- linux共享存储通信实验,Linux进程通信——共享存储
- 有感而发,恍然大悟。
- DDD领域驱动设计特点及难点
- 对于一颗具有n个结点,度为4的树来说,( )
- 实时流媒体编程基于Linux环境开发
- 【clickhouse】ClickHouseException code: 999 Cannot allocate block number in ZooKeeper: Coordination
- matlab自带python_在matlab中直接在python中使用sklearn
- C++_const修饰指针_指针和数组_指针和函数_指针配合数组和函数案例_用指针数组实现冒泡排序---C++语言工作笔记024
- SQLite的基本使用
- 【LeetCode】205 Isomorphic Strings (c++实现)
- Python--turtle.circle()参数说明
- 2:Carmaker+Simulink+Canoe联合仿真,搭建ADAS HIL测试环境
- JAVA常用类 ——Random类
- 史上最简单的封装教程,五分钟学会封装系统(以封装Windows 7为例)
- linux安装源文件出现错误,编译安装源码时出现错误的解决方法
- [c++] 计算太阳高度角
- 微信小程序学习之路——API媒体
- LabVIEW控制Arduino采集DHT11温湿度数值(进阶篇—4)
- 股票自动交易软件接口支持的语言是什么?
- zookeeper设置密码
热门文章
- leetcode_day02
- Centos如何通过yum安装php7
- kettle的hello world
- 无法找到脚本文件 C:/Windows/explorer.exe:574323188.vbs
- 在 Linux 上部署 Django 应用,nginx+gunicorn+supervisor
- [转载] python type() 判断数据类型
- [转载] 使用Python在ArcGIS中编程杂谈
- 图片的色彩空间转换、简单色彩跟踪与通道分离、合并(三)
- os.path的使用
- Maximal Binary Matrix CodeForces - 803A (贪心+实现)