试图将PHP代码转换为VB.net

时间:2013-02-17 11:07:56

标签: vb.net

我的PHP代码是

$geourl = 'http://maps.google.com/maps/geo?key=' . $google_apikey . 
    '&output=json'. '&q=' . urlencode($_GET['url'] . ', USA').'&gl=us';

我的ASPX代码看起来像这样

Dim google_apikey As String="sdasdasd"    
Dim geourl As String= "http://maps.google.com/maps/geo?key=" & google_apikey & _
   "&output=json" & "&q=" & urlencode(request.QueryString("pc")& ", USA")"&gl=us"

我得到的错误是编译器错误消息:BC30205:预期语句结束。

而不是句号(。)我用过&它在vb.net中是否有效,上面的字符串urlencode有什么问题?

2 个答案:

答案 0 :(得分:1)

认为你最后错过了一个连锁器。应该是:

Dim geourl As String= "http://maps.google.com/maps/geo?key=" & google_apikey & _
     "&output=json" & "&q=" & UrlEncode(request.QueryString("pc")& ", USA") & _
     "&gl=us"

答案 1 :(得分:0)

我建议您使用String.Format方法使代码更具可读性:

Dim google_apikey As String="sdasdasd"    
Dim geourl As String = String.Format("http://maps.google.com/maps/geo?key={0}&output=json&q={1},USA&gl=us", UrlEncode(google_apikey), UrlEncode(Request.QueryString("pc")))