{"contents":[{"productID":34,"productName":"SuperWidget"},{"productID":56,"productName":"WonderWidget"}]}
從遠端拉取的資料
private void saveFile() {
try {
FileOutputStream fileOutputStream = openFileOutput("123.txt",
Context.MODE_PRIVATE);
fileOutputStream.write(resource.getBytes());
fileOutputStream.flush();
fileOutputStream.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
Toast.makeText(JSONExampleActivity.this, "儲存成功", Toast.LENGTH_LONG).show();
}儲存在Internal Storage之後讀取 private void readFile() {
String temp = null;
try {
FileInputStream fileInputStream = openFileInput("123.txt");
int length = fileInputStream.available();
byte[] buffer = new byte[length];
fileInputStream.read(buffer);
fileInputStream.close();
temp = new String(buffer);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
請問readFile()內的temp 要如何才會被這段執行呢?
JSONArray test = temp.getJSONArray("contents");我知道宣告錯誤我也試過把它變成JSONObject型態 但是都還是錯誤 請高人指點 謝謝 已爬過多文
解决方案 »
- android编译错误,麻烦看下,谢谢
- Notification中怎么传值给下一个Activity
- android 源码下编译自己的项目,mm时提示make: *** 没有规则可以创建...需要的目标“out/target/product/generic/ob
- android网络数据流量监控
- htc g6 能装ANDRIOD 2.3吗?
- Eclipse中为什么不能抓图
- eclipse 更新后出现问题
- 大神们,本人想自己闲余时间开发一个自己的APP,怎么搭建服务器。
- 求教大神~~怎么把android自带的TimePicker 做成IOS的风格?
- Android studio 运行按钮是灰色的,不能运行
- 如何动态删除button按钮s
- Android显示word和pdf文档,要如何实现呢
JSONObject obj = array.get(i);
String str = obj.getString("productID");
}