이상한 문제가 있습니다. 저는 초보자이지만 XML 문서에서 정보를 추출하는 방법을 배우려고합니다. 전에 아무런 문제없이 해봤지만 지금은 문제가 있습니다. 여기 무슨 일이야 : 다음 코드를 사용하여문자열을 int로 변환 할 수 없습니다. XML 요소의 데이터입니다. C#
<ip2locationapi>
<countryCode>GB</countryCode>
<countryName>United Kingdom</countryName>
<region>Wales</region>
<city>Cardiff</city>
<latitude>51.5</latitude>
<longitude>-3.2</longitude>
</ip2locationapi>
:
나는 다음과 같은 XML에서 latitude
값을 추출하려고 시도
var latitude = from r in document.Descendants("ip2locationapi")
select new
{
lati = r.Element("latitude").Value,
};
foreach (var item in latitude)
{
Convert.ToInt32(item.lati);
}
을하지만이 일을하는 것은 나에게 말하고, 나에게 예외를 제공합니다 잘못된 형식이므로 변환 할 수 없습니다.
내가 잘못하고있는 사람이 누구인지 알고 있습니까?
될 것 Convert.ToInt32 (Convert.ToDouble (item.lati)); 그렇지 않으면 Convert.ToDouble. –
@MPatel 이것을 위해'Converter' 물건을 호출 할 필요가 없습니다. '(int) Convert.ToDouble (item.lati)'이면 충분합니다. – BartoszKP
@BartoszKP 공정한 점 : 나는 그것을 생각하지 않았다! –