Created
November 15, 2012 16:11
-
-
Save homelinen/4079431 to your computer and use it in GitHub Desktop.
Very Simple JSON Parser
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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