-2

i have to get value in this json array

{"certificates":[
{"alias":"CSTQUE","hsm":"HSM2","cf":"XXXXX","email":"xxx@xxx.it","cell":"+12345678"},
{"alias":"AXO","hsm":"HSM2","cf":"XXXXX","email":"xxxx@xxx.it","cell":"+12345678"}]}

How can I get all of these variable with same name in Java? Can I iterate them or can I do getString("alias") and get both values?

Bezkup
  • 1
  • 3
  • 1
    step one is to turn that string data, which JSON is, into a Java object. You do that by looking up which package/method does that, and then reading their API documentation that explains what kind of object you are going to get back. Java doesn't come with a built in JSON parser, so you get to [search and research](/help/how-to-ask) which options there are (there's a few very commonly used ones) and read up on how they work. – Mike 'Pomax' Kamermans Dec 06 '20 at 16:13

1 Answers1

-2

you have to iterate throw them first then you can access the variables in every object like this

JSONArray array = theNameOfYourJsonObject.getJSONArray("certificates");
for(int i = 0; i < array.lengh; i++){
JSONObject object = arrey.get(i);
//now you have an object of the array
String alias = object.getString("alias");
}
m_yasin
  • 17
  • 1
  • 5