【发布时间】:2015-11-18 21:47:30
【问题描述】:
我有一个应用程序,我可以在其中获取一个 json 并从中读出。 要测试我的应用程序,需要一个包含 json 的文件。 问题是我不能像在 C# 中那样从我的电脑中获取它。 所以我创建了一个资产文件夹并将我的文件放入其中。 现在我有了这个代码:
BufferedReader r = null;
AssetManager a = getAssets();
StringBuilder s = new StringBuilder();
try{
r = new BufferedReader(new InputStreamReader(a.open("My.json"), "UTF-8"));
String l;
while((l = r.readLine()) != null){
s.append(l);
}
JSONObject g = new JSONObject(s.toString());
每次我运行它并进入 while 循环时,调试器都会说没有可用的帧。我在循环中和之后都有断点,即使我等待很长时间,它们也不会被击中。 我做错了什么还是有其他更好的方法可以从我的文本文件中获取 jsonObject?
【问题讨论】:
标签: android json file android-studio