public String GetAllProjectByNameFileExcept(String NameFile)
{
JSONObject output_json = new JSONObject();
ArrayList<String> List = new ArrayList<String>();
DB db = null;
try
{
db = MONGODB.GetMongoDB();
DBCollection collLocal = db.getCollection("local");
BasicDBObject objek_db = new BasicDBObject();
BasicDBObject objek_db2 = new BasicDBObject();
objek_db.put("$ne", NameFile);
objek_db2.put("_id",objek_db);
DBCursor cursor = collLocal.find(objek_db2);
while (cursor.hasNext()) {
List.add(cursor.next().get("_id").toString());
}
if (List.size() == 0)
{
output_json.put("code", 0);
output_json.put("message", "Not Found");
output_json.put("data", null);
}else
{
output_json.put("code", 1);
output_json.put("message", "Success");
output_json.put("data", List);
}
}
catch (Exception e)
{
output_json.put("code", -1);
output_json.put("message",e.toString());
}
return output_json.toString();
}
我有功能GetAllProjectByNameFileExcept返回值:(寧靜)解析與JSONValue.parse Java錯誤JSON
{"code":1,"data":[A11.2011.05900.pdf, A11.2011.05930.pdf, A11.2011.05931.pdf, A11.2011.05932.pdf],"message":"Success"}
類型數據[A11.2011.05900.pdf,...,n.pdf]是ArrayList的字符串
我叫其他功能這一功能:
String list = this.GetAllProjectByNameFileExcept(NameFile);
output_json.put("result", list);
我被檢查輸出:
{"result":"{\"code\":1,\"data\":[A11.2011.05900.pdf, A11.2011.05930.pdf, A11.2011.05931.pdf, A11.2011.05932.pdf],\"message\":\"Success\"}"}
但如果列表解析與此代碼:
JSONObject FileData = (JSONObject) JSONValue.parse(list);
總是得到錯誤
java.lang.Error: Error: could not match input
org.json.simple.JSONValue.parse(Unknown Source)
service.CrawLocal.PlagiarismCheck(CrawLocal.java:276)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
代碼在其他功能sucess解析我認爲錯誤,因爲ArrayList字符串類型的數據..我該怎麼辦?
我認爲你的方法有問題。你需要顯示你的方法的代碼「GetAllProjectByNameFileExcept(NameFile);」看看究竟是什麼。 – 2015-03-03 04:00:19
done @NomeshDeSilva。 – Orlando 2015-03-03 04:06:29
將您的json字符串格式化爲將雙引號括在您的數組中,例如[「A11.2011.05900.pdf」,「A11.2011.05930.pdf」,...]。我認爲這是你當前的json字符串無效的問題。檢查我的答案。 – 2015-03-03 04:10:42