Skip to content

Instantly share code, notes, and snippets.

@homelinen
Created November 15, 2012 16:11
Show Gist options
  • Save homelinen/4079431 to your computer and use it in GitHub Desktop.
Save homelinen/4079431 to your computer and use it in GitHub Desktop.
Very Simple JSON Parser
import java.io.*;
import java.util.Map;
import static java.nio.file.Files.newBufferedReader;
import static java.nio.file.Paths.get;
import static java.nio.charset.Charset.defaultCharset;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
public class PathFinder {
public static void main(String[] args) {
JSONParser parse = new JSONParser();
JSONArray array = new JSONArray();
try {
BufferedReader reader = new BufferedReader(new FileReader(new File("links.json")));
Object obj = parse.parse(reader);
array = (JSONArray)obj;
reader.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch ( IOException ioE) {
ioE.printStackTrace();
} catch (ParseException pE) {
pE.printStackTrace();
}
Map<String, Object> tempMap;
for (Object obj: array) {
tempMap = (Map<String, Object>)obj;
System.out.println(tempMap.get("weight").toString() + tempMap.get("city1").toString() + tempMap.get("city2"));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment