0

用于起点和终点之间长距离的 Google 距离矩阵 API 在大于 1000 公里时以空格响应:“1 865”

当我尝试使用 LINQ 订购结果时:

.OrderBy(g => Double.Parse(g.Distance, CultureInfo.GetCultureInfo("pt-PT")))

我得到错误:

System.FormatException: Input string was not in a correct format.
at System.Number.ParseDouble(String value, NumberStyles options, NumberFormatInfo numfmt)

我尝试使用 g.Distance.replace(" ","") 删除空格,但它不起作用。

4

1 回答 1

0

调试 Google Distance Matrix API 返回的字符串后,我发现字符是 Chr(160) 并删除它我使用了函数(直接在 API 的返回值中):

.Replace(Convert.ToChar(160).ToString(), "");

现在我可以毫无问题地订购:

.OrderBy(g => Double.Parse(g.Distance, CultureInfo.GetCultureInfo("pt-PT")))
于 2015-08-31T21:22:30.003 回答