当我访问此URI时,我得到了一个Json对象列表:
personUri = https://myuri.com/get/listOfPeople/
JSON
[{"firstName":"Tom","lastName":"Blue"},{"firstName":"Susan","lastName":"Summers"},{"firstName":"Albert","lastName":"Smith"}]
爪哇:
List<People>persons = new ArrayList<>();
UriComponentsBuilder componentsBuilder = UriComponentsBuilder.fromHttpUrl(personUri);
String jsonInfo = getRestTemplate().getForEntity(componentsBuilder.toUriString(), String.class).getBody();
LOG.debug("REST RESPONSE: "+jsonInfo);
Gson gson = new Gson();
Type type=new TypeToken<List<People>>(){}.getType();
persons=gson.fromJson(jsonInfo,type);
我收到此错误。
预计BEGIN_ARRAY但在第1行第62列STRING
这是因为我需要使用HashMap.class而不是String.class吗?
VO
public class People {
private String firstName;
private String lastName;
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
}