[英]Extract json string array value from json object using java
從下面 json object 我必須使用 java 提取錯誤摘要錯誤原因。 我附上了我正在使用的示例代碼,因為我收到了 json 異常錯誤。
{
"errorCode": "xxxx",
"errorSummary": "xxxxxx",
"errorLink": "xxxx",
"errorId": "xxxxx",
"errorCauses": [
{
"errorSummary": "Get the error summary"
}
]
}
我正在使用下面的代碼來提取errorCause,但它拋出了錯誤。
public String getExceptionMessage(MyRestTemplateException ex) {
try {
String Json = ex.getMessage();
JSONObject json = new JSONObject(Json);
JSONObject jsonData = new JSONObject();
// String ExceptonMsg = json.getString("errorSummary");
JSONObject errCause = new JSONObject(json.getString("errorCauses"));
LOGGER.info("jsonArr AES " +errCause.toString());
return errCause.toString();
} catch (Exception e) {
LOGGER.error("Error while get exception message: " + e.toString());
}
return null;
}
有人可以幫我解決這個問題嗎?
代替
JSONObject errCause = new JSONObject(json.getString("errorCauses"));
和
JSONObject errCause = jsonObj.getJSONArray("errorCauses");
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.