This method reads text from json file.I want to read only name,date,time from json file.How can I accomplish this.My json file contains various records each record consisting of name,lat,lon,image_name,date,time.I need to read name,date,time of one record and place it as radio button1 value then read second name,date,time of second record and place it in radio butto2 value. I also need to delete specific name and update specific name. Please help me and Thank You in advance.Have a great day ahead.
String root = Environment.getExternalStorageDirectory().toString(); //get access to directory path
File myDir = new File(root + "/GeoPark");//create folder in internal storage
myDir.mkdirs();// make directory
File file = new File(myDir, FILENAME);//making a new file in the folder
if(file.exists()) // check if file exist
{
//Read text from file
StringBuilder text = new StringBuilder();
try {
BufferedReader br = new BufferedReader(new FileReader(file));
String line;
while ((line = br.readLine()) != null) {
text.append(line);
}
}
catch (IOException e) {
//You'll need to add proper error handling here
}
//Set the text
String x=text.toString();
String z=x.replace("{","").replace("date:","").replace("time:","").replace("Record:","").replace("[","").replace("latitude:","").replace("longitude:","").replace("name:","").replace("address:","").replace("pin:","").replace("area:","").replace("image:","").replace("\"","").replace("]","").replace("}","");
String[] y=z.split(",");
rb1.setText(y[3].toString()+","+y[7].toString()+","+y[8].toString());
}
else
{
rb1.setText("Sorry file doesn't exist!!");
}
This is my json file
{Record:["lat":"22.5835","lon":"88.456","name":"aa","add":"cc",date:30/04/2018,time:21:05:10]}
{Record:["lat":"22.583544","lon":"88.45642","name":"BB","add":"cc",date:30/04/2018,time:21:05:40]}