Open gbolcer opened 3 years ago
matrix-synapse 1.58.1, python 3.9, java11 x64, Ubuntu 22.04lts curl http://localhost:8008/_synapse/admin/v1/server_version {"server_version":"1.58.1","python_version":"3.9.5"}
org.json.JSONException: JSONObject["invite"] not found. at org.json.JSONObject.get(JSONObject.java:573) at org.json.JSONObject.getJSONObject(JSONObject.java:766) at de.jojii.matrixclientserver.Bot.Events.RoomEvent.parseAllEvents(RoomEvent.java:59) at de.jojii.matrixclientserver.Bot.Syncee.lambda$2(Syncee.java:124) at java.base/java.lang.Thread.run(Thread.java:829)
Not sure this is doing the right thing, but it fixes the jsonobject error.
public static List<RoomEvent> parseAllEvents(JSONObject object) {
List<RoomEvent> roomEvents = new ArrayList<>();
String[] pointsTOP = {"join", "invite", "leave"};
for (String pointTop : pointsTOP) {
//System.out.println(object.toString());
JSONObject object1 = null;
Iterator<String> keys = null;
String raw_event = object.toString();
if (raw_event.contains("rooms") && raw_event.contains(pointTop)) {
try {
object1 = object.getJSONObject("rooms").getJSONObject(pointTop);
keys = object1.keys();
while (keys != null && keys.hasNext()) {
String key = keys.next();
JSONObject room = object1.getJSONObject(key);
String[] points = {"timeline", "state", "account_data", "ephemeral", "invite_state"};
for (String point : points) {
if (!room.has(point)) {
continue;
}
JSONArray timeline = room.getJSONObject(point).getJSONArray("events");
for (int i = 0; i < timeline.length(); i++) {
JSONObject event = timeline.getJSONObject(i);
roomEvents.add(fetchRoomEvent(event, key));
}
}
}
} catch (org.json.JSONException e) {
System.out.println("json exception in room events." + e.getMessage());
}
}
}
return roomEvents;
}
Hi! I tried to reproduce the error, but couldn't. Could you provide the JSON-String, which causes the problem.
curl http://localhost:8008/_synapse/admin/v1/server_version {"server_version":"1.42.0","python_version":"3.8.10"}
org.json.JSONException: JSONObject["rooms"] not found. at org.json.JSONObject.get(JSONObject.java:473) at org.json.JSONObject.getJSONObject(JSONObject.java:573) at de.jojii.matrixclientserver.Bot.Events.RoomEvent.parseAllEvents(RoomEvent.java:57) at de.jojii.matrixclientserver.Bot.Syncee.lambda$2(Syncee.java:124)