0
如何處理這一點,以便它不會提供以下錯誤如何知道JSON字符串是否可以無錯轉換爲JSONObject?
JSONObject dataObject = new JSONObject(data);
String currentDynamicKey = "7";
JSONObject currentDynamicValue = dataObject.getJSONObject(currentDynamicKey);
錯誤:
org.json.JSONException: Value at 7 of type java.lang.String cannot be converted to JSONObject
JSON數據:
{"2":{"id":2,"title":"Battleship game","enabled":"1","connection_alert":"1","prot":"2","port":"6410","analysis":"1","send_data":"Analysis Data box","regex":"\/HTTP\/1.1 404 Not Found\/","send_on":false,"analysis_alert_title":"404","analysis_alert_body":"not found","analysis_alert_body_false":"found"},"7":""}
,你可以在最後的7見空。我能做些什麼來檢查它是否爲空?
你正在使用哪個json解析器?有幾十個,它們都有一個JSONObject或JsonObject類。 –
這是一個Android應用程序 – Waqleh