I have a short question concerning Java. I am trying to find/get a function to do the following in Java which I did in PHP. The PHP code looks like this:
PHP:
$var = file_get_contents("https://api.example.com/json); //get json file
$var = json_decode($var, true); // decode json file to multidimensional array
I then can go on and read the values like this:
$firstname = $var["person data"]["firstname"]; //first container is "person data" which has a couple of values, too (like firstname)
$surname = $var["person data"]["surname"]; // and so on
.
This is what I got now (Java):
URLConnection connection = new URL("https://example.com/json").openConnection();
try(Scanner scanner = new Scanner(connection.getInputStream());){
String response = scanner.useDelimiter("\\A").next();
System.out.println(response);
}
I get some kind of object in "response" but I am not able to convert it to an array like in the PHP code above. I tried a lot of other suggested solutions which I found on google, but I am not able to do this.
So, to sum it up. Basically, what I want to do is:
Pseudocode:
get json from link;
convert json to array;
read array; // like: $var = result[0][5];
Can someone help me?