我正在使用web服务:
public static final String URI2 = "http://www.webservicex.net/length.asmx/ChangeLengthUnit?LengthValue=10.0&fromLengthUnit=Centimeters&toLengthUnit=Inches";
RestTemplate restTemplate = new RestTemplate();
String usersMap2 = restTemplate.getForObject(URI2, String.class);
我将响应作为字符串:
<?xml version="1.0" encoding="utf-8"?>
<double xmlns="http://www.webserviceX.NET/">3.9370078740157477</double>
如何将其解析为可读和可用的格式。
答案 0 :(得分:0)
我猜你可以这样做DoubleWrapper usersMap2 = restTemplate.getForObject(URI2, DoubleWrapper.class);
@XmlRootElement(name="double", namespace="http://www.webserviceX.NET/")
@XmlAccessorType(XmlAccessType.FIELD)
public class DoubleWrapper{
@XmlValue
private Double value;
//Getter and setter
}