掲示板
To extract data from jSON array
10年前 に Kannan G krishnan によって更新されました。
To extract data from jSON array
Regular Member 投稿: 121 参加年月日: 13/04/30 最新の投稿
Hi community,
I have a requirement in my project that i want to retrieve data from a JSON url like
I am trying to get the data from the jBPM workflow part. When i load this url i got the window with some display like,
I believe the values are there in the array. I want to store each of the values in different variables.
i used the code like,
But this is not working. How can i do this in liferay??
Regards
Kannan G.krishnan
I have a requirement in my project that i want to retrieve data from a JSON url like
localhost:8080/gwt-console-server/rs/process/instance/258/activeNodeInfo
I am trying to get the data from the jBPM workflow part. When i load this url i got the window with some display like,
[{"width":932,"height":541,"activeNode":{"name":"id\u003d13","x":662,"y":123,"width":118,"height":40}}]
I believe the values are there in the array. I want to store each of the values in different variables.
i used the code like,
try {
List<string> result = new ArrayList<string>();
String url = "http://localhost:8080/gwt-console-server/rs/process/instance/258/activeNodeInfo";
String json = HttpUtil.decodePath(url);
JSONObject resultJsonObject = new JSONObject(json);
JSONArray jsonArray = resultJsonObject.getJSONArray("results");
System.out.println("jsonArray-->"+jsonArray);
String name = null;
for (int index = 0, total = jsonArray.length(); index < total; index++) {
final JSONObject jsonObject = jsonArray.getJSONObject(index);
name = jsonObject.getString("name");
result.add(name);
}
System.out.println("result-->"+result);
} catch (JSONException e) {
throw new RuntimeException(e+"here");
}</string></string>
But this is not working. How can i do this in liferay??
Regards
Kannan G.krishnan
10年前 に meera prince によって更新されました。
RE: To extract data from jSON array
Liferay Legend 投稿: 1111 参加年月日: 11/02/08 最新の投稿
Hi
You are getting response is JSON array so frst create JSON array object not JSON Object
Try following code
Regards,
Meera Price
You are getting response is JSON array so frst create JSON array object not JSON Object
Try following code
String json = HttpUtil.decodePath(url);
JSONArray jsonArray = JSONFactoryUtil.createJSONArray(json);
for (int index = 0;index < jsonArray.length(); index++) {
JSONObject jsonObject = jsonArray.getJSONObject(index);
System.out.println("width"+jsonObject.getString("width"));
System.out.println("width"+jsonObject.getString("height"));
JSONObject activeNodeJsonObject = jsonObject.getJSONObject("activeNode");
System.out.println("Name"+activeNodeJsonObject.getString("name"));
System.out.println("X"+activeNodeJsonObject.getString("x"));
System.out.println("Y"+activeNodeJsonObject.getString("y"));
}
Regards,
Meera Price