我有一個包含代表一些形狀像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