春の初心者です。http://api.engin.umich.edu/hostinfo/...PONT&room=B505の API 呼び出しから JSON オブジェクトの配列を取得するための非常に単純なコードを作成しました。
「名前:NULL」のみ取得
import org.springframework.web.client.RestTemplate;
public class Application {
public static void main(String args[]) {
RestTemplate restTemplate = new RestTemplate();
Computer[] computer = restTemplate.getForObject("http://api.engin.umich.edu/hostinfo/v1/computers.json?building=PIERPONT&room=B505", Computer[].class);
System.out.println("Name: " + computer[0].getName());
}
}
ここでは、単純なコンピューター クラスを実行します。
package hello;
import org.codehaus.jackson.annotate.JsonIgnoreProperties;
@JsonIgnoreProperties(ignoreUnknown = true)
public class Computer {
private String hostname;
public String getName() {
return hostname;
}
public String toString() {
return "Computer [hostname=" + hostname + "]";
}
}