我正在嘗試從https://ip-api.com檢索資料。我已經請求了多個變數,并且想附加每一行不同的資料。我有一個文本框,并在同一個鏈接請求中請求了多個變數。
讓我舉一個我現在擁有的例子。
WebClient wc = new WebClient();
string results = wc.DownloadString("http://ip-api.com/line/?fields=status,message,continent,continentCode,country,countryCode,region,regionName,city,district,zip,lat,lon,timezone,offset,currency,isp,org,as,asname,reverse,mobile,proxy,hosting,query");
textBox1.Text = results;
輸出如下
successNorth AmericaNAUnited StatesUScensoredForPrivacy
我希望它看起來像這樣
success
North America
NA
United States
US
CensoredForPrivacy
我怎樣才能用我提供的方式來做到這一點,或者還有其他方式嗎?
uj5u.com熱心網友回復:
該WebClient方法DownloadString將附加 LF 換行符 (\n) 但TextBox需要 CRLF 換行符 (\r\n)。
這可以通過在\n然后使用拆分來解決AppendText(Environment.NewLine)
string results = wc.DownloadString("http://ip-api.com/line/?fields=status,message,continent,continentCode,country,countryCode,region,regionName,city,district,zip,lat,lon,timezone,offset,currency,isp,org,as,asname,reverse,mobile,proxy,hosting,query");
string[] headers = results.split("\n");
foreach(string s in headers) {
textBox1.AppendText(s);
textBox1.AppendText(Environment.NewLine);
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/431270.html
上一篇:將自定義有效負載按鈕鏈接到意圖
