-1

I have a json file that contains lots of field which i want to seperate so that i can use it as each different field.Basically i want to split them and store them as each individual field so that i can use that file with the mysql.Json File Snippet

tangocharlie7
  • 33
  • 1
  • 7

1 Answers1

1

It looks like that this are JSONObjects line by line (no arrays). Read the file line by line and create a JSONObject with that line.

BufferedReader br = new BufferedReader(new FileReader(file));
String line;
while ((line = br.readLine()) != null) {
  JSONObject json = new JSONObject(line);
  //json.getString("Slaves");
  //json.getStrng("Job Reader");

//and so on..

//if you want to get all avilable keys.. use
    Iterator<?> keys = json.keys();

    while( keys.hasNext() ){
        String key = (String)keys.next();
        if( json.get(key) instanceof JSONObject ){
            //key = the key and json.get(key) the value.
        }
    }
}
br.close();
Emanuel
  • 8,027
  • 2
  • 37
  • 56
  • 2
    -1? wtf... for what? this is a working example matching this case. – Emanuel Jul 22 '14 at 21:48
  • could you please elaborate this portion particularly the commented portion of what logic shoud i use , i am novice to java: if( json.get(key) instanceof JSONObject ){ //key = the key and json.get(key) the value. } – tangocharlie7 Jul 23 '14 at 16:14