-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

8
  • I am not familiar so much, but it should be an json parser for that? Commented Jul 22, 2014 at 21:43
  • 3
    Enter code instead of screenshot. Commented Jul 22, 2014 at 21:43
  • 2
    Why 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? Commented Jul 22, 2014 at 21:44
  • 4
    Go to json.org. At the bottom of the page are listed maybe 20 different kits for parsing JSON in Java. Use one. Commented 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 Tree Commented Jul 22, 2014 at 22:48

1 Answer 1

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();
Sign up to request clarification or add additional context in comments.

2 Comments

-1? wtf... for what? this is a working example matching this case.
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. }

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.