So I have this much code to start off (I included the import because I thought you might want to see what I imported):
import java.sql.Array;
import java.util.Map;
import org.json.simple.*;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
import dataProcessing.Config.Config;
import java.io.*;
public class Reader {
private String file_path;
private FileReader fReader;
public Reader(String filePath) {
this.file_path = filePath;
try {
fReader = new FileReader(file_path);
} catch (Exception e) {
e.printStackTrace();
}
}
public Config read() {
Config c = new Config();
JSONParser parser = new JSONParser();
Object obj = null;
try {
obj = parser.parse(fReader);
} catch (Exception e){
//ignore this
}
JSONObject jsonobj = (JSONObject) obj;
if (jsonobj != null) {
c.dailyWorkTime = (Long) jsonobj.get("dailyWorkTime");
c.dburl = (String) jsonobj.get("db_url");
c.username = (String) jsonobj.get("username");
c.password = (String) jsonobj.get("password");
c.millis = (Long) jsonobj.get("millis");
}
return c;
}
}
The import thing is that Right now I can't write arrays in my JSON file. Basically I can't do stuff like :
{
"database_info": {
"db_url": "hi",
"username": "root",
"password": "root"
},
"system_configuration": {
"dailyWorkTime": 22,
"millis": 600000
},
"entries": {
"organization": [
"orgid","orgname","orgprojects"
],
"store" : [
"stid","stname","st_belong_org"
],
"customers" :[
"phonenumber","facebookid","twitterid","instagramid"
]
}
}
Anyway other stuff is not important. The only thing I really need to parse is "entries", into something like String[][] or Map. Rightnow to use jsonobj.get() I must have direct entry name in my json file. Can anyone help? :D Thanks.