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 ==