1

I'm trying to read parameters for a function from a JSON file, but I always got a empty string.
This is my JSON file

{
    "prova":"https://urltest",
    "reale":"https://url"
}

and my code is

    String key_param = "folder/param.json";
    File param = new File ("/tmp/" + key_param);
    /*
       ...
       CODE FOR CHECKING FILE EXISTENCE
       ...
    */
    JSONParser new_pars = new JSONParser();
    Reader myreader = new FileReader(param); 
    JSONObject json_param = (JSONObject) new_pars.parse(myreader);
    String url = new String();
    if (ambiente == "prova") //<-- this has been previously set in the code
        url = (String) json_param.get("prova");
    else if (ambiente == "reale")
        url = (String) json_param.get("reale");

    System.out.println("url = " + url);

I always get url = from the execution.
What's wrong?

EDIT
It's not the json handling which is faulty, but my attempt to compare strings in Java using ==

shark_sh
  • 111
  • 1
  • 12

1 Answers1

2

Are there any errors when you use jsonobject.get(value) ?

Same as @Dave Newton's answer. You can not compare to string with operation ==. You should use equals or equalsIgnorecase to compare