Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Check if nested value the same as a variable

I have a small question,
I mean I have a little problem…

I try to check if a a json nested value the same as a variable,
they are, but my debug say they are not, but they are exactly the same.

String license_key = "--license-key--";

    try {
        JSONObject json = JSONReader.readJsonFromUrl("https://api.chunkfactory.com?pid=1279&key=" + license_key);
        JSONObject innerLicense = json.getJSONObject("license");
        
        if (innerLicense.getString("license_key") == license_key) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    } catch (IOException e) {
        e.printStackTrace();
    }

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

for comparison of strings , we should use the equals method and not the == operator.
The == operator just compares the references and equals method checks if they have the same value.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading