c# 代码 编译出现常量中有换行符错误

使用问题 · 631 次浏览
ARS 创建于 2023-10-07 10:50

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("获取成功!");
}

 


回复内容
CL 2023-10-07 11:24
#1

代码里少了引号。


CL 回复 CL 2023-10-07 11:25 :

可以用v2模式,这样调试运行的时候可以看到行的对应关系,比较方便定位错误。看起来里面应该缺少不止一个引号。


ARS 2023-10-07 11:29
#2

emmm好吧,Quicker的c#代码好像不支持${变量}的这种写法我才稍微改了一下,没改全所以出现了这种错误

v2确实可以,报错很详细,我再查查。谢谢崔神

CL 回复 ARS 2023-10-07 11:30 :

v2 支持这种写法,是基于Roslyn引擎的,支持比较新的c#语法。

回复主贴