Java JsonParser parse json file

Description

Java JsonParser parse json file

import java.io.FileReader;
import java.io.Reader;

import javax.json.Json;
import javax.json.stream.JsonParser;
import javax.json.stream.JsonParser.Event;

public class Main {

   public static void main(String[] args) throws Exception {
      Reader fileReader = new FileReader("BookObject.json");
      JsonParser parser = Json.createParser(fileReader);

      while (parser.hasNext()) {
         Event ev = parser.next();
         System.out.println(ev);// w w  w. java  2s.c o  m
         if (ev.equals(Event.VALUE_STRING)) {
            System.out.println(parser.getString());
         }
      }
   }
}



PreviousNext

Related