c#的代码我是从VS中直接粘贴到Quicker中的并进行了少许修改,但是一直提示出现常量中有换行符错误。从网上查了一下很多都说是编码的问题,但是Quicker中好像没有设置编码的地方。请问有没有解决的方案?
以下是尝试执行的代码:
//.cs 文件类型,便于外部编辑时使用
// 引用必要的命名空间
using System.Windows.Forms;
using Newtonsoft.Json.Linq;
using OfficeOpenXml;
using System.Net;
using System.Text;
public class SingleDaHangHai
{
public long uid { get; set; }
public long ruid { get; set; }
public string username { get; set; }
public int guard_level { get; set; }
}
public static List<SingleDaHangHai> getDaHangHai(string roomID, string uid)
{
List<SingleDaHangHai> daHangHais = new List<SingleDaHangHai>();
int pageIdx = 1;
string url = "https://api.live.bilibili.com/xlive/app-room/v2/guardTab/topList?roomid=" + roomID + "&page=" + pageIdx + "&ruid" + uid";
JObject o = JObject.Parse(GetRequest(url));
int totalDaHangHai = (int)o["data"]["info"]["num"];
JArray top3 = (JArray)o["data"]["top3"];
foreach (var dhh in top3)
{
daHangHais.Add(
new SingleDaHangHai
{
uid = (long)dhh["uid"],
ruid = (long)dhh["ruid"],
username = (string)dhh["username"],
guard_level = (int)dhh["guard_level"]
});
}
//总页数
int totalPages = (int)o["data"]["info"]["page"];
for (int i = 1; i <= totalPages; i++)
{
if (i != 1)
{
url = "https://api.live.bilibili.com/xlive/app-room/v2/guardTab/topList?roomid="+ roomID + "&page=" + i + "&ruid=" + uid";
o = JObject.Parse(GetRequest(url));
}
//列表
JArray list = (JArray)o["data"]["list"];
foreach (var dhh in list)
{
daHangHais.Add(
new SingleDaHangHai
{
uid = (long)dhh["uid"],
ruid = (long)dhh["ruid"],
username = (string)dhh["username"],
guard_level = (int)dhh["guard_level"]
});
}
}
if (daHangHais.Count != totalDaHangHai)
{
return null;
}
return daHangHais;
}
public static string GetRequest(string url)
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.Method = "GET";
request.ContentType = "text/html;charset=UFT-8";
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream stream = response.GetResponseStream();
StreamReader reader = new StreamReader(stream, Encoding.UTF8);
String retString = reader.ReadToEnd();
reader.Close();
stream.Close();
return retString;
}
// Quicker将会调用的函数
public static void Exec(Quicker.Public.IStepContext context)
{
//var oldValue = context.GetVarValue("varName"); // 读取动作里的变量值
//MessageBox.Show(oldValue as string);
//context.SetVarValue("varName", "从脚本输出的内容。"); // 向变量里输出值
//List<SingleDaHangHai> DHH = getDaHangHai();
//MessageBox.Show("获取成功!");
}