【发布时间】:2014-12-25 16:21:00
【问题描述】:
我的问题是解析二维数组并修复错误。下面是我的 jason 文件、java 代码和错误列表。
这是我的 Json 文件:[
{
"elementaryProductId":1,
"bonusMalus":30,
"deductible":500,
"comprehensive":1,
"partial":0,
"legacyPremium":130,
"product":{
"productId":2,
"garage":"true",
"constructionYear":1990,
"region":"East",
"dateOfBirthYoungest":"1983-06-22",
"objectValue":25000,
"type":"Car"
}
},
这是我的 java 代码,我认为问题在于定义第二个数组:
try {
FileReader reader = new FileReader(filePath);
JSONParser jsonParser = new JSONParser();
JSONArray jsonArray = (JSONArray) jsonParser.parse(reader);
Iterator i = jsonArray.iterator();
while (i.hasNext()){
JSONObject object = (JSONObject) i.next();
.
.
.
JSONArray productArray = (JSONArray) jsonParser.parse("product");
Iterator j = productArray.iterator();
while (j.hasNext())
{
JSONObject product = (JSONObject) j.next();
long productId = (Long) product.get("productId");
System.out.println("The id is: " + productId);
}`
错误列表:Unexpected character (p) at position 0.
at org.json.simple.parser.Yylex.yylex(Yylex.java:610)
at org.json.simple.parser.JSONParser.nextToken(JSONParser.java:269)
at org.json.simple.parser.JSONParser.parse(JSONParser.java:118)
at org.json.simple.parser.JSONParser.parse(JSONParser.java:81)
at org.json.simple.parser.JSONParser.parse(JSONParser.java:75)
at com.domain.project.SveUMain.main(SveUMain.java:66)
【问题讨论】: