[英]Parsing JSON fails with not a JSONArray
I am trying to parse the following JSON in Java program. 我正在尝试在Java程序中解析以下JSON。
JSON JSON格式
{
"data": {
"pageIDentifier":" nametitle",
"page": {
"pageID”:” sports_league_member",
"platform":" www",
"activityType":" ent",
"businessUnit":" ent",
"productLOB":" ent",
"productOffered":" abc",
"productQualifier”:” abc:a bc”,
"flowType”:” sports_com”,
"pageDesc”:” desc”,
"attributes": {
"pageType":" www",
"host”:” finaluser”,
"appId”:” SportsAppID_user”,
"daEnvironment”:” releaser”,
"jvm":" ent_logon_01",
"xCKey":" SportsAppID_user",
"daUID":" jddc9yu5pi1yy6",
"sysEnv”:” user”,
"uri”:” /www/sportscenter”,
"daPageName":" "
}
}
}
}
JAVA Program JAVA程序
URL url = getClass().getResource("test.json");
File file = new File(url.getPath());
String jsonData = readFile(file.getAbsolutePath());
JSONObject jobj = new JSONObject(jsonData);
JSONArray jarr = new JSONArray(jobj.getJSONArray("data").toString());
System.out.println("jarr: " + jarr);
I am getting the following error when executing this code. 执行此代码时出现以下错误。 Please note, jsonData is giving the entire json string without any issue. 请注意, jsonData给出了整个json字符串,没有任何问题。
org.json.JSONException: JSONObject["data"] is not a JSONArray. org.json.JSONException:JSONObject [“ data”]不是JSONArray。
How can i parse "data" value from the above json value? 我该如何解析上述json值中的“数据”值? Please advise. 请指教。
data
is not an array data
不是数组
Try this : 尝试这个 :
System.out.println("jarr: " + jobj.getJSONObject("data").toString());
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.