gpt4 book ai didi

c# - Visual Studio 2015 在 Text Visualizer 上截断长字符串

转载 作者:太空宇宙 更新时间:2023-11-03 15:24:19 24 4
gpt4 key购买 nike

更新:经过一些研究,我发现这是 Visual Studio 2015 和 Text Visualizer 的问题,您可以查看 here .

要重现它,打开 QuickWatch (Shift+F9) 并在搜索框中输入 new string(' ', 32769)。之后单击放大镜玻璃,您应该会在字符串中间看到一个“...”...

所以,改变我的问题,有没有办法解决这个问题并使其不被截断,这样我就可以在没有变通方法的情况下进行复制?



我有这段代码:

        JArray bundlesJson = (JArray)JObject.Parse(System.IO.File.ReadAllText(Server.MapPath("~/itens.json")))["bundles"]; // file "itens.json" can be found at http://pastebin.com/7K15yAVd
System.Text.RegularExpressions.Regex rgx = new System.Text.RegularExpressions.Regex(@"(?<sNome>.*?)\/(?<sClasse>.*?)\/(?<sDescricao>.*?)(?:\/(?<sExtras>.*?)\n|\n|$)");
var text = System.IO.File.ReadAllText(Server.MapPath("~/TextFile1.txt")); // TextFile1.txt is too big to put here, so i've uploaded it here: http://pastebin.com/AtxbYPXc

var matches = rgx.Matches(text);
var lstItens = new List<Item>();
var oJson = new JArray();

foreach (System.Text.RegularExpressions.Match match in matches)
{
var item = new Item()
{
sClasse = match.Groups["sClasse"].Value.Trim(),
sDescricao = match.Groups["sDescricao"].Value.Trim(),
sNome = match.Groups["sNome"].Value.Trim(),
sExtras = match.Groups["sExtras"].Value.Trim(),
};
item.PreencherListaBundles(bundlesJson.ToString());

lstItens.Add(item);
}
var result = JsonConvert.SerializeObject(lstItens, Formatting.Indented);
var backResult = JsonConvert.DeserializeObject<List<Item>>(result);

lstItens 列表正确包含所有项目(501 项),但 result 字符串在搜索 "Nome"时仅返回 48 个对象:,这是必填字段。为什么会这样?

为了举例说明错误,如果您搜索 "Nome":"Fiddlehead Fern,请在 result var 中查找项目 lstItens[166] " 你可以看到该项目不存在......

奇怪的是 backResult.Count 将显示 501 个结果,并且似乎包含所有项目,但在 result var 生成的 json 中进行简单搜索必填字段“Nome”将产生 48 个结果,如图所示:48 results


Item.cs:


public class Item
{
[JsonProperty(PropertyName = "Nome")]
public string sNome { get; set; }

[JsonProperty(PropertyName = "Classe")]
public string sClasse { get; set; }

[JsonProperty(PropertyName = "Descricao")]
public string sDescricao { get; set; }

[JsonProperty(PropertyName = "Extras")]
public string sExtras { get; set; }

[JsonProperty(PropertyName = "Bundles")]
public List<Bundle> lstBundles { get; set; }

public void PreencherListaBundles(string jsonBundles)
{
List<Bundle> lstBundle = JsonConvert.DeserializeObject<List<Bundle>>(jsonBundles.ToString());

this.lstBundles = new List<Bundle>();

lstBundle.ForEach(x =>
{
if (!lstBundles.Select(y => y.sNome).Contains(x.sNome) && x.lstItens.Select(y => y.sNome).Contains(sNome))
{
lstBundles.Add(new Bundle() { sLocal = x.sLocal, sNome = x.sNome, sRecompensa = x.sRecompensa, lstItens = x.lstItens });
}
});
}
}

Bundle.cs


public class Bundle
{
[JsonProperty(PropertyName = "bundle")]
public string sNome { get; set; }

[JsonProperty(PropertyName = "location")]
public string sLocal { get; set; }

[JsonProperty(PropertyName = "reward")]
public string sRecompensa { get; set; }

[JsonProperty(PropertyName = "items")]
public List<BundleItem> lstItens { get; set; }

public class BundleItem
{
[JsonProperty(PropertyName = "name")]
public string sNome { get; set; }

[JsonProperty(PropertyName = "description")]
public string sDescricao { get; set; }

[JsonProperty(PropertyName = "quantity")]
public int nQuantidade { get; set; }

[JsonProperty(PropertyName = "quality")]
public string sQualidade { get; set; }
}
}

编辑: 看起来某些机器上没有出现该错误,就像您在 Gerard Sexton 的回答中看到的那样,但是当我运行他运行的相同代码时,我仍然得到 48 个结果。可以在此讨论中找到更多详细信息:https://chat.stackoverflow.com/rooms/106307/discussion-between-gerard-sexton-and-gabriel-duarte

最佳答案

试试这个:

var result = JsonConvert.SerializeObject(lstItens, Formatting.Indented);
//Testing deserialization
var backResult = JsonConvert.DeserializeObject<List<Item>>(result);

结果变量是一个包含格式正确的字符串的字符串。

关于c# - Visual Studio 2015 在 Text Visualizer 上截断长字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35992255/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com