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.
-
I am not familiar so much, but it should be an json parser for that?Kick Buttowski– Kick Buttowski2014-07-22 21:43:28 +00:00Commented Jul 22, 2014 at 21:43
-
3Enter code instead of screenshot.bartektartanus– bartektartanus2014-07-22 21:43:51 +00:00Commented Jul 22, 2014 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– Boris the Spider2014-07-22 21:44:12 +00:00Commented Jul 22, 2014 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– Hot Licks2014-07-22 21:46:08 +00:00Commented Jul 22, 2014 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 Treetangocharlie7– tangocharlie72014-07-22 22:48:25 +00:00Commented Jul 22, 2014 at 22:48
|
Show 3 more comments
1 Answer
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();
2 Comments
Emanuel
-1? wtf... for what? this is a working example matching this case.
tangocharlie7
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. }