我搜索了所有相关线程,但没有成功,欢迎任何相关答案。
.json
我在文件夹内的 SDCard 中有一个 JSON 数据作为.NewFolder
文件,我想读取文件中的数据并解析,找到时间戳,如果时间戳不同,我想重写它。
下面是我使用的代码,我得到了数据aBuffer
和值,jdata_fromfile
但是在解析时我得到了 nullPointerException。
myFile = new File(Environment.getExternalStorageDirectory() + "/.NewFolder/" +str.get(i));
if(myFile.exists())
{
FileInputStream fIn = new FileInputStream(myFile);
BufferedReader myReader = new BufferedReader(new InputStreamReader(fIn));
String aDataRow = "";
String aBuffer = "";
while ((aDataRow = myReader.readLine()) != null)
{
aBuffer += aDataRow;
}
myReader.close();
jdata_fromfile = new JSONObject(aBuffer);
String timestamp_fromfile = jdata_fromfile.getString(str_timestamp.get(i));
timestamp_val_fromfile.add(timestamp_fromfile);
}
else
{
myFile.createNewFile();
writedate_tofile(value_json.toString());
timestamp_val_fromfile.add("xxx");
}
而且,当我在记事本中打开文件时,它都在一行中,仅显示部分数据,当我复制到http://jsonformatter.curiousconcept.com时
我得到了全部数据和一个有效的 json 。当我这样做时,我可以在记事本中看到其余数据 - ctrl+end 并按 enter 。
为什么会这样,我哪里出错了?
这是我的错误 - 日志
02-13 18:44:52.109: E/aBuffer value(7134): is {"Status":{"Itemlist":[{"x - Drinks":{"Details":[{"type":"","image":"","price":"","name":"Minerals"},{"type":"","image":"","price":"","name":"Milk Shakes"},{"type":"","image":"","price":"","name":"Milk"},{"type":"","image":"","price":"","name":"Mineral Water"},{"type":"","image":"","price":"","name":"Hot Beverages"},{"type":"","image":"","price":"","name":"Chocolate Muffin and Ice Cream"}, ........................................................................{"type":"","image":"","price":"","name":"Blu
02-13 18:44:52.189: E/jdata_fromfile value(7134): is {"x Time_stamp":"2013-02-12 12:30:00","Status":{"Itemlist":[{"x - Sides":{"Details":[{"type":"","image":"","name":"Onion Rings (6)","price":""},{"type":"","image":"","name":"Sausage Portion (Minimum 2 per portion)","price":""},.................................................................................................................... ,"x - Burgers":{"Details":[{"type":"","image":"","name":"x 5oz Burger","price":""},{"type":"","image":"","name":"x 5oz Cheese Burger","price":""},{"type":"","image":"","name":"x 5oz with Bacon and Cheese","price":""},{"type":"","imag
02-13 18:44:52.189: E/Reading from internal file - Exception e(7134): java.lang.NullPointerException
提前致谢 。