简体   繁体   中英

How to check if json file contains specific value or not

I was wondering, I"m looking to add update button in my fragment which when user click will check if updates available or not .

I"m looking for solution on How to acess json file from url and check if json value contains new value or not . if key matches to the already specified value then display message you data has been updated and if not then display No updates availaible.

For Example if below is the json file

[
   {
           "updateKey": "1"

      }
]

and if it contains other then 1 then show toast message with updates availaible.

To access data from a url you can use retrofit https://square.github.io/retrofit/ when you get e JSON response you can verify if exist key using JSONObject

json = new JSONObject(response);
if (json.has(<key>)) { }

Something similar to this one https://stackoverflow.com/a/43341909/10931055

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