IllegalArgumentException JSON.
-
12-11-2019 - |
質問
jsonObjectで文字列[]を入れようとしています。
java.lang.IllegalArgumentException:無効な値のタイプ。タイプ: [[Ljava.lang.String;]値:[[ljava.lang.string; @ 189db56] com.ibm.json.java.jsonObject.put(jsonObject.java:241)
これを解決するのを手伝ってください。 ありがとう
Public 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); }
解決
を試してください
jsonObject.put("yourKey", Arrays.asList(yorStringArray));
.
マニュアルを読む必要があるので http://www.json.org/javadoc/org/json/jsonObject.html Object[]
を期待することが期待されていません
他のヒント
多分あなたは google-gson 。
JavaのJSONを扱うことが非常に好きです。
所属していません StackOverflow