2012-02-24 2 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

答えて

0

が期待していないお読みくださいとおり

jsonObject.put("yourKey", Arrays.asList(yorStringArray)); 

てみますgoogle-gsonをご覧ください。

は、私はそれが非常にJavaでJSONで仕事をしたいです。

関連する問題