It's my first time working with a JSON file, so I went with simple JSON library. Here's what works:
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
public class ParseCardJSON {
public static void main(String[] args) {
JSONParser parser = new JSONParser();
Object obj;
try {
obj = parser.parse(new FileReader("C:\\Users\\owner\\Desktop\\A\\programming\\workspace\\MTG\\AllSets.json"));
JSONObject jsonObject = (JSONObject) obj;
System.out.println(obj.toString());
String name = (String) jsonObject.get("name");
String color = (String) jsonObject.get("power");
System.out.println("Name: " + name);
System.out.println("color: " + color);
} catch (Exception e) {
e.printStackTrace();
}
}
}
So the System.out.println(obj.toString()); prints out what I'm expecting:
({"LEA":{"name":"Limited Edition Alpha","code":"LEA","gathererCode":"1E","magicCardsInfoCode":"al","releaseDate":"1993-08-05","..)...
but the "name" and "color" prinlns are null. Any idea what could be wrong?