0

I'm calling a method which returns a json response.

call:

String domainTermJson = getTermJson(domainTermId,client,gson);

Response:

{"assigned_assets":{"items":[{"_type":"database_column","_id":"b1c497ce.60641b50.42lla3a9f.di3kgbf.q6iaov.51q42k0equhf2ept2cgts","_url":"https://cs2cislp02.bns:9443/ibm/iis/igc-rest/v1/assets/b1c497ce.60641b50.42lla3a9f.di3kgbf.q6iaov.51q42k0equhf2ept2cgts","_name":"__AC_DEAACC"},{"_type":"database_column","_id":"b1c497ce.60641b50.42lla491l.o39k1ru.63p48q.57h74d2s5llcll4e429ji","_url":.
.
.
.etc...

What I am trying to do is capture all the _id values into a string seperated by a comma. Example below:

String dc_id = "b1c497ce.60641b50.42lla3a9f.di3kgbf.q6iaov.51q42k0equhf2ept2cgts", "b1c497ce.60641b50.42lla491l.o39k1ru.63p48q.57h74d2s5llcll4e429ji"

How can I do this with a json response?

1
  • There are many ways to do this and many tools that can help. What technologies are you using? Commented Apr 20, 2017 at 18:46

2 Answers 2

0

Loop through the JSON response like this and assign the attribute ID to the string in each iteration like this : dc_id+=objectInArray.getString("_id");

Sign up to request clarification or add additional context in comments.

Comments

0

You could use JSONObject library in order to get that.

JSONObject jsonObject = new JSONObject(getTermJson(domainTermId,client,gson));
JSONObject list = jsonObject.getJSONObject("assigned_assets").getJSONObject("items");
JSONArray arr = new JSONArray(list);
List<String> ids = new ArrayList<>();
for (int i = 0; i < arr.length(); i++) {
    JSONObject obj = arr.getJSONObject(i);
    ids.add(obj.get("_id").toString());
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.