2012-02-24 125 views
0

我试图把字符串[]中的JSONObject并获得以下错误抛出:IllegalArgumentException JSON

java.lang.IllegalArgumentException异常:无效的类型的值。类型: [[Ljava.lang.String]与值:[[Ljava.lang.String; @ 189db56]在 com.ibm.json.java.JSONObject.put(JSONObject.java:241)

请帮我解决这个问题。 感谢

公众的JSONObject toJSONObject(){

JSONObject jsonObject = new JSONObject(); 

    //Use reflection to get a list of all get methods 
    //and add there corresponding values to the JSON object 
    Class cl = dto.getClass(); 
    logger.infoFormat("Converting {0} to JSON Object", cl.getName()); 
    Method[] methods = cl.getDeclaredMethods(); 

    for (Method method : methods) { 
     String methodName = method.getName(); 
     if (methodName.startsWith("get")) { 
      logger.infoFormat("Processing method - {0}", methodName); 
      //Check for no parameters 
      if (method.getParameterTypes().length == 0) { 
       String tag = getLabel(method); 
       Object tagValue = new Object(); 

       try { 
        tagValue = method.invoke(dto); 
       } catch (Exception e) { 
        logger.errorFormat("Error invoking method - {0}", method.getName()); 
       } 

       if (method.getReturnType().isAssignableFrom(BaseDTO.class)) { 
        DTOSerializer serializer = new DTOSerializer((BaseDTO) tagValue); 
        jsonObject.put(tag, serializer.toJSONObject()); 
       } else if (method.getReturnType().isAssignableFrom(List.class)) { 
        ListSerializer serializer = new ListSerializer((List<BaseDTO>) tagValue);      
        jsonObject.put(tag, serializer.toJSONArray());     
       } else {      
        if (tagValue != null) jsonObject.put(tag, tagValue); 
       } 
      } 
     } 
    } 

    return(jsonObject); 
} 
+1

显示您的代码... – shift66 2012-02-24 11:11:27

回答

相关问题