这是我的包装类,
public class JSON2Apex {
public class JSON2Apex {
public List<Results> results;
public String status;
}
public class Location {
public Double lat;
public Double lng;
}
public static JSON2Apex parse(String json) {
return (JSON2Apex) System.JSON.deserialize(json, JSON2Apex.class);
}
}
我的顶点控制器是,
public class callout
{
@future(callout=true)
public static void callout(String add,Id cntid)
{
Http http = new Http();
HttpRequest req = new HttpRequest();
req.setEndpoint('https://maps.googleapis.com/maps/api/geocode/json?address='+add+'&key=AIzaSyDvf7W2SWXwUPXy8X2PSIGM6NwVusZywx4');
req.setMethod('GET');
HTTPResponse res = http.send(req);
if(res.getStatusCode()==200)
{
JSON2Apex2 obj = (JSON2Apex2 )JSON.deserialize(res.getBody(), JSON2Apex2.class);
System.debug('Here I want to diplay lat and lng values');
}
}
}
这里我想在apex控制器的location方法中显示lat和lng值,怎么做?
答案 0 :(得分:0)
目前你不能,因为你没有内部类的实例作为外部类的属性,所以它不作为类的一部分公开。您需要像currentLocation或类似的属性。
编辑更新媒体资源名称的答案:
public class JSON2Apex {
public Location location {get; set;}
public class JSON2Apex {
public List<Results> results;
public String status;
}
public class Location {
public Double lat;
public Double lng;
}
public static JSON2Apex parse(String json) {
return (JSON2Apex) System.JSON.deserialize(json, JSON2Apex.class);
}
}
然后在你的其他代码示例中,它将是
System.debug('Here I want to diplay lat and lng values' + obj.location.lat + ' ' + obj.location.lng);