我从服务响应中得到 JSONObject。
好吧,如果发生错误,我需要将其转换为错误类之一。
Json 有点像
{"message":"This means that the userID is not valid.","name":"UserNotFoundException"}
其中 name 可以是模型包中的任何异常
我可以这样做吗?
Class ex = Class.forName("com.myapp.model.Exceptions." + jsonObject.getString("name"));
如何将 ex 转换为 UserNotFoundException 类,以便我可以使用它的方法,即 ex.doSomething()