지금 나는 지금 내가 메서드를 호출 할 때 유형마다 시간을 변경해야? 일반적인 방법으로 변경하는 key.How에서 된 JSONObject 데이터를 얻을 수있는 일반적인 방법을 쓰기.내 메소드를 일반 메소드로 변경하는 방법은 무엇입니까?
String a= (String) ObdDeviceTool.getResultData(result, "a", String.class);
Double b= (Double) ObdDeviceTool.getResultData(result, "b", Double.class);
public static Object getJSONObjectData(JSONObject result,String key,Object type){
if (result.containsKey(key)) {
if(type.equals(String.class))
return result.getString(key);
if(type.equals(Double.class))
return result.getDouble(key);
if(type.equals(Long.class))
return result.getLong(key);
if(type.equals(Integer.class))
return result.getInt(key);
}
return null;
}
@ JonnyHenly 시도해 보았지만 변경할 수 없습니다. public static T getJSONObjectData (JSONObject 결과, String 키, T 유형) –
flower