2013-08-12 39 views
1

的信息,我有字符串(例如)JSON文件:採取從JSON文件c#

@{ 
"Url": "http://site.com/?q=windows8" 
} 

我怎樣才能把信息?q=後C#(Windows 8中)。對不起我的英語不好。

+2

[檢查了這一點(http://stackoverflow.com/questions/659887/get-url-parameters-from-a-string-in-net) – musefan

+1

有一個看看:HTTP:// stackoverflow.com/questions/659887/get-url-parameters-from-a-string-in-net –

回答

1

你可以做簡單:?

字符串s =「myURL/Q = windows8的「;

// Loop through all instances of ?q= 
int i = 0; 
while ((i = s.IndexOf("?q=", i)) != -1) 
{ 

    // Print out the substring. Here : windows8 
    Console.WriteLine(s.Substring(i)); 

    // Increment the index. 
    i++; 
} 
2

您可以使用查詢字符串。

在代碼隱藏文件

public String q 
{ 
    get 
    { 
     if (Request.QueryString["q"] == null) 
      return String.Empty; 
     return Convert.ToString(Request.QueryString["q"]); 
    } 
} 

然後使用下面的一行來獲取值

var index = ('<%=q%>');