简体   繁体   中英

Retrieve data from a specific array from a json

I have a admin app written with Java to be able to manage my users

I created a custom json

This is what my JSON looks like

[
  {
    "userId": 1,
    "email": "user1@gmail.com",
    "sponsorship": true,
    "create": 274
  },
  {
    "userId": 2,
    "email": "user2@gmail.com",
    "sponsorship": false,
    "create": 201
  },
  {
    "userId": 3,
    "email": "user3@gmail.com",
    "sponsorship": false,
    "create": 189
  }
]

In my List I just display email address

Now my problem, for example if I click on the List which contains the email user1@gmail.com , I want to display in a Dialog the data related to this email, ie the userId , sponsorship and create

How ​​can I retrieve the other values ​​using the email?

I couldn't find anything about it on the internet

When reading your json file, you need to make it understandable. There is an example of making it understandable in the link below.

You have to write a condition after these procedures. The condition should be:

for(int i=0; i< employeeList.size;i++){
    if(employeeList[i].email.equals("user3@gmail.com")){
//the person you are looking for
var person = employeeList[i];
}
}

https://howtodoinjava.com/java/library/json-simple-read-write-json-examples/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM