I am attempting to traverse an api recursively to produce an end result of the type:
1
/ \ \ \
/ \ \ \
/ \ \ \
2 3 0 7
\ / \
4 5 6 10
/ / \
7 8 9
The issue I am finding is that I understand that I can use something similar to http://rosettacode.org/wiki/Tree_traversal#Java But fail to understand how to recursively make a NEW call on the api?
The API accepts the following input: http://example.com/1/children
To return:
{
"name": "1",
"children": [{
"name": "2"
}, {
"name": "3"
}]
}
How would I then continue to make a call on 2 to find it's children and then do the same for 3 once all the children for 2 are found?
Sample code:
import java.net.*;
import java.io.*;
public class URLConnectionReader {
public static void main(String[] args) throws Exception {
URL yahoo = new URL("http://example.com/1/children");
URLConnection yc = yahoo.openConnection();
BufferedReader in = new BufferedReader(
new InputStreamReader(
yc.getInputStream()));
String inputLine;
while ((inputLine = in.readLine()) != null)
System.out.println(inputLine);
in.close();
}
}