我有一个包含代表一些形状像JSON数组JSON文件,意外的字符(J)67
[{"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]}
]
错误
Unexpected character (j) at position 67.
这里是我的代码来解析这个
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;
}
我想读这个文件并创建这些形状并返回形状的数组,但我得到的任何错误的LP?
_but我得到errors_那是** **所有你必须说或者想告诉我们** **哪个错误? – 2014-11-06 15:36:18
如果您可以告诉我们您使用的是哪个JSON解析器,它也将有所帮助。 – 2014-11-06 15:38:50
这不是您发布的错误。这是一个堆栈跟踪_没有错误信息。 – 2014-11-06 15:39:33