我創建了一個包含我的Json數據的java URL類,並且有一些函數可以獲取我的json數據以進行一些數據比較,但我發現它可能不支持JSONObject將數據傳遞到JSONObject。我是否需要在我的情況下使用JSONArray,因爲我的JSON數據也有數組結構?
使用JSONObject以URL格式傳遞Json數據的任何方法?
try
{
JSONObject obj = new JSONObject();
obj.readJsonFromUrl(theUrl);
System.out.println(obj.toString());
}
catch(MalformedURLException e)
{
System.out.print("your problem here ...1");
}
}
else
{
System.out.print("Can't Connect");
}
我相信,這是地方給我的錯誤消息,因爲它返回我這個錯誤在我的編譯器
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
The method readJsonFromUrl(URL) is undefined for the type JSONObject
也有一定的警示作用消息爲JSONObject readJsonFromUrl方法
private static JSONObject readJsonFromUrl(URL theUrl) throws IOException, JSONException {
任何人都可以向我解釋JSON數據如何在java中工作?我看到了很多JSON類的Java類,這讓我很困惑,比如JSONObject,JSONArray,JSONValue。我在網上搜索了一些資料,但我也對此不是很清楚,因爲我是很新的JSON數據處理
這是我的樣本JSON數據,我需要的數據scan_result僅
{
"data_id":"a71a3c2588c6472bb4daea41a0b58835",
"file_info":{
"display_name":"",
"file_size":242,
"file_type":"Not available",
"file_type_description":"Not available",
"md5":"aa69ba384f22d0dc0551ace2fbb9ad55",
"sha1":"09ceb54e65df3d3086b222e8643acffe451a6e8a",
"sha256":"dcb46d6ae2a187f789c12f19c44bbe4b9a43bd200a3b306d5e9c1fcf811dc430",
"upload_timestamp":"2016-11-18T09:09:08.390Z"
},
"process_info":{
"blocked_reason":"",
"file_type_skipped_scan":false,
"post_processing":{
"actions_failed":"",
"actions_ran":"",
"converted_destination":"",
"converted_to":"",
"copy_move_destination":""
},
"profile":"File scan",
"progress_percentage":100,
"result":"Allowed",
"user_agent":""
},
"scan_results":{
"data_id":"a71a3c2588c6472bb4daea41a0b58835",
"progress_percentage":100,
"scan_all_result_a":"No Threat Detected",
"scan_all_result_i":0,
"scan_details":{
"Ahnlab":{
"def_time":"2016-11-08T15:00:00.000Z",
"location":"local",
"scan_result_i":0,
"scan_time":1,
"threat_found":""
},
"Avira":{
"def_time":"2016-11-08T00:00:00.000Z",
"location":"local",
"scan_result_i":0,
"scan_time":133,
"threat_found":""
},
"ClamAV":{
"def_time":"2016-11-08T10:28:00.000Z",
"location":"local",
"scan_result_i":0,
"scan_time":94,
"threat_found":""
},
"ESET":{
"def_time":"2016-11-08T00:00:00.000Z",
"location":"local",
"scan_result_i":0,
"scan_time":38,
"threat_found":""
}
},
"start_time":"2016-11-18T09:09:08.405Z",
"total_avs":4,
"total_time":250
},
"vulnerability_info":{
}
}
你確定readJsonFromUrl方法裏面有JSONOBject類嗎? – SpringLearner
@SpringLearner - 我嘗試更改getJsonObject,並向我顯示相同的錯誤消息。你會在JSONObject中推薦任何合適的方法嗎? –
你指的是JavaEE7中的'javax.json.JSONObject'嗎? –