我正在尝试在方法中调用一个restclient,包括解析数据,她的代码我希望在方法中做出所有这些,请提出任何想法:
public void Convert(object value, Type targetType, object parameter, CultureInfo culture){RestClient client = new RestClient();
client.BaseUrl = "http://";
RestRequest request = new RestRequest();
request.Method = Method.GET;
request.AddParameter("action", "REE");
request.AddParameter("atm_longitude", location.Longitude);
client.ExecuteAsync(request, ParseFeedCallBack_ListDistance);}
public void ParseFeedCallBack_ListDistance(IRestResponse response){
if (response.StatusCode == HttpStatusCode.OK)
{
ParseXMLFeedDistance(response.Content);
}
private string ParseXMLFeedDistance(string feed)
{
.... return myvalueToBind;
}
答案 0 :(得分:0)
我做了类似这样的事情,但它没有为每个项目调用ParseXMLFeedDistance:
foreach (var resp in xmlItems2.Descendants("result"))
{
RestClient client = new RestClient();
client.BaseUrl = "http://";
RestRequest request = new RestRequest();
request.Method = Method.GET;
request.AddParameter("action", "atms_distances");
request.AddParameter("lang", "ar");
request.AddParameter("mode", "xml");
request.AddParameter("appli", "WP");
request.AddParameter("mobile_latitude", "35.843283");
request.AddParameter("mobile_longitude", "10.61617");
request.AddParameter("atm_latitude", resp.Element("Lattitude"));
request.AddParameter("atm_longitude",resp.Element("longitude"));
// client.ExecuteAsync(request, ParseFeedCallBack_ListDistance);
client.ExecuteAsync(request, response =>
{
ParseXMLFeedDistance(response.Content);
});
}
private void ParseXMLFeedDistance(string feed)
{
if (feed == null)
return;
try
{
XElement xmlItems = XElement.Parse(feed);
XDocument xmlItems2 = XDocument.Parse(feed);
var list = new List<State>();
foreach (XElement val in xmlItems2.Descendants("result").Last().Elements())
{
// distance = val.Value;
list.Add(new State
{
TotalDistance = val.Value,
});
}
ResultSearch_ListDistance.ItemsSource = list;
}
catch
{
}
}