-3

Edited. Anyone know how to read the record in every new line. The below code can only read 1 sentence.

JSONParser parser = new JSONParser(); try { Object obj = parser.parse(new FileReader("src/test.json")); JSONObject jsonObject = (JSONObject) obj; String name = (String) jsonObject.get("name"); System.out.println(name); } 
4
  • 3
    stackoverflow.com/questions/8939250/parsing-json-file-java Commented Jun 18, 2013 at 4:02
  • You can use any JSON parsing libs like Jackson. Commented Jun 18, 2013 at 4:02
  • I followed the download here link and it is a zip file and add external library to eclipse but still have error after inserting import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; Commented Jun 18, 2013 at 4:33
  • please post your json file, thing is once you have got the jsonobject then you need to iterate/fetch from the object based on your json structure. Commented Jun 18, 2013 at 14:50

2 Answers 2

1

Many ways. I suggest you use google-gson

Sign up to request clarification or add additional context in comments.

Comments

0

You can use codehouse jackson

ObjectMapper mapper = new ObjectMapper(); BufferedReader br = new BufferedReader(new FileReader(tweets)); Map<String, Object> json_as_map = mapper.readValue(br, new TypeReference<Map<String, Object>>() {}); 

After that you can traverse your map or arraylist according to ur structure.

1 Comment

You have to add search.maven.org/remotecontent?filepath=org/codehaus/jackson/… in your classpath. And then use JAVA Collection APIs to parse JSON.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.