I have a json file which contains json array representing some shapes like that,
[{"Cordinates": [272.0,81.0,200.0,100.0],
"Type":"Ellipse2D",
"Color":java.awt.Color[r=255,g=0,b=0]},
{"Cordinates":[227.0,272.0,200.0,100.0],
"Type":"Rectangle2D",
"Color":java.awt.Color[r=255,g=0,b=0]}
]
the errors
Unexpected character (j) at position 67.
And here is my code to parse this
public List<ShapeItem> read() {
try {
Object obj = parser.parse(new FileReader(filePath));
JSONArray ja = (JSONArray)obj;
for (int j = 0; j < ja.size(); j++){
JSONObject si = (JSONObject) ja.get(j);
String type = (String) si.get("Type");
JSONArray cordinates = (JSONArray) si.get("Cordinates");
Float x, y, width, height;
x = (Float) cordinates.get(0);
y = (Float) cordinates.get(1);
width = (Float) cordinates.get(2);
height = (Float) cordinates.get(3);
if (type.equals("Ellipse2D")){
s = new Ellipse2D.Float(x, y, width, height);
}
else if (type.equals("Rectangle2D")){
s = new Rectangle2D.Float(x, y, width, height);
}
c = (Color) si.get("Color");
shapeItem = new ShapeItem(s, c);
shapes.add(shapeItem);
}
}
return shapes;
}
I want to read this file and create those shapes and return array of shapes but i got errors any help?