Planned maintenance is scheduled for the week of June 15th - the exact date and time will be announced soon.
See More Details
Ask Questions and Find Answers
Important:
Ask is now read-only. You can review any existing questions and answers, but not add anything new.
But - don't panic! While ask is no more, we've replaced it with discuss - the new Liferay Discussion Forum! Read more here here or just visit the site here:
discuss.liferay.com
To extract data from jSON array
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/activeNodeInfoI 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
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
Community
Company
Feedback