我已經編寫了用於從file.j文件生成json搜索數據的java代碼,但它沒有生成確切的JsonArray。它像Json數組生成不正確
[{"item":"1617"},{"item":"1617"}]
,而不是
[{"item":"747"},{"item":"1617"}].
這裏1617是從文件中取得最後一個項目。
JSONArray ja = new JSONArray();
JSONObject jo = new JSONObject();
while (products.readRecord())
{
String productID = products.get("user");
int j = Integer.parseInt(productID);
if(j == userId) {
itemid = products.get("item");
jo.put("item",itemid);
ja.add(jo);
}
}
out.println(ja);
products.close();
你嘗試過調試..? – jabal 2012-03-21 20:44:30