[英]Extract json string array value from json object using java
From below json object i have to extract the errorSummary with in errorCauses using java.从下面 json object 我必须使用 java 提取错误摘要错误原因。 i have attached the sample code which i am using in that i am getting a json exception error.我附上了我正在使用的示例代码,因为我收到了 json 异常错误。
{
"errorCode": "xxxx",
"errorSummary": "xxxxxx",
"errorLink": "xxxx",
"errorId": "xxxxx",
"errorCauses": [
{
"errorSummary": "Get the error summary"
}
]
}
i am using below code to extract the errorCause but it's throwing error.我正在使用下面的代码来提取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;
}
Could some one help me to resolve this issue?有人可以帮我解决这个问题吗?
Replace代替
JSONObject errCause = new JSONObject(json.getString("errorCauses"));
with和
JSONObject errCause = jsonObj.getJSONArray("errorCauses");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.