Hi Shiva,
You can access the json array by using following method.
JSONArray dataArray = jsonResponseObject.get("data");
for( int i = 0; i < dataArray.length; i++){
JSONObject data = dataArray.getJSONObject(i);
String deploymentID = dataArray.getString("deploymentId");
}
Regards,
Firzhan
On Thu, Jan 22, 2015 at 5:06 PM, Shiva Balachandran <[email protected]> wrote:
> Hi,
>
> Im really confused on what would be the method to query a JSON Object
> inside a JSON Object. I have the following JSON String, what i did was use
> the JSONObject Class present in org.json package.
>
> The JSON structure to be queried is as follows,
>
> {
> "data": [
> {
>
> "deploymentId": "233",
> "deploymentUrl":
> "http:\/\/localhost:8080\/activiti-rest\/service\/repository\/deployments\/2220"
> },
> {
>
> "deploymentId": "123",
> "deploymentUrl":
> "http:\/\/localhost:8080\/activiti-rest\/service\/repository\/deployments\/2110"
> },
> {
>
> "deploymentId": "202,
> "deploymentUrl":
> "http:\/\/localhost:8080\/activiti-rest\/service\/repository\/deployments\/2440",
>
> }
> ],
> "total": 8,
> "start": 0,
> "sort": "name",
> "order": "asc",
> "size": 8
> }
>
>
> So i wrote this code to query this JSON string,
>
> JSONObject jsonResponseObject = new JSONObject(responseData);
> JSONArray data = new JSONArray(jsonResponseObject.get("data"));
>
> int responseObjectSize =
> Integer.parseInt(jsonResponseObject.getString("total"));
>
> for(int j=0; j < responseObjectSize; j++){
> if (data.getJSONObject(j).getString("deploymentId").equals(deploymentID)){
> System.out.println("Success");
> definitionId = data.getJSONObject(j).getString("id");
> }
> }
>
> This code is not working, am i not accessing the data part correctly?
>
> --
> Shiva Balachandran
> Software Engineer
> WSO2 Inc.
>
> Mobile - +94 774445788
>
> _______________________________________________
> Dev mailing list
> [email protected]
> http://wso2.org/cgi-bin/mailman/listinfo/dev
>
>
_______________________________________________
Dev mailing list
[email protected]
http://wso2.org/cgi-bin/mailman/listinfo/dev