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.
Asked
Active
Viewed 2,336 times
-1

tangocharlie7
- 33
- 1
- 7
-
I am not familiar so much, but it should be an json parser for that? – Kick Buttowski Jul 22 '14 at 21:43
-
3Enter code instead of screenshot. – bartektartanus Jul 22 '14 at 21:43
-
2Why post an (illegible) screenshot rather than a sample of the file? Have you tried anything or would you like us to write some free code for you? – Boris the Spider Jul 22 '14 at 21:44
-
4Go to json.org. At the bottom of the page are listed maybe 20 different kits for parsing JSON in Java. Use one. – Hot Licks Jul 22 '14 at 21:46
-
{"Slaves":"1","kdt build Box Gen":"0.00323034008","Job Render":"19.1420002","Adaptation Luminance":"0.00553634018","LightMan finalize PA":"6.93000004e-07","GeomMan finalize Total":"0.163755","IES bytes":"0","KDTree Kickstart":"0.0291175991","Indirect Tree – tangocharlie7 Jul 22 '14 at 22:48
-
i want to seperate each field – tangocharlie7 Jul 22 '14 at 22:49
-
how to use JSON parser. I Don't know. Could you please provide pointers for that – tangocharlie7 Jul 23 '14 at 17:32
-
There is this thing called "Google". Or you can use the little search line in the upper right corner of this page. There are literally thousands of examples of parsing JSON in Java here in SO. – Hot Licks Jul 23 '14 at 20:14
1 Answers
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
-
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