2013-08-19 37 views
-3

我写了代码belown,我想获取经纬度值,但我不知道如何去做。我想学习获取列表中的元素。获取列表中的元素

public class GeoCode 
{ 
    public List<Results> Results { get; set; } 
} 
public class Results 
{   
    public Geometry geometry { get; set; } 

    public class Geometry 
    { 
     public LL location { get; set; } 
     public ViewPort viewPort { get; set; } 
    } 
    public class LL 
    { 
     public double lat { get; set; } 
     public double lng { get; set; } 
    } 
    public class ViewPort 
    { 
     public LL northeast { get; set; } 
     public LL southwest { get; set; } 
    } 
} 
+0

您需要扩展您的问题。你想从特定属性的列表中获取元素吗? – DGibbs

+2

'Results [0]'返回第一个元素,'foreach(结果中的var res循环遍历所有这些元素,你试图获得什么? – Sayse

+0

我想在结果列表中获取元素“lat”和“lng” –

回答

3
var yourList = yourGeoCode.Results 
          .Select(x=>x.geometry.location).ToList(); 

它将返回的LL其中有2个属性latlng列表。如果你想获得该元素的latlng在指数2,试试这个:

double lat = yourList[2].lat; 
double lng = yourList[2].lng; 

注:您应该为属性的第一个字母大写,例如,Latlat