C# 要列出的Json格式字符串
我有这样一个字符串:C# 要列出的Json格式字符串,c#,json,string,list,C#,Json,String,List,我有这样一个字符串: {"label":{"en":"Africa","de":"Afrika"},"description":{"en":"continent","de":"irdischer Kontinent"}} var result = input.Replace(":{", " - ") .Replace("},", Environment.NewLine) .Replace("{", string.Empty
{"label":{"en":"Africa","de":"Afrika"},"description":{"en":"continent","de":"irdischer Kontinent"}}
var result = input.Replace(":{", " - ")
.Replace("},", Environment.NewLine)
.Replace("{", string.Empty)
.Replace("}", string.Empty);
可以转换为如下列表:
"label" - "en":"Africa","de":"Afrika"
"description" - "en":"continent","de":"irdischer Kontinent"
谢谢正如其他人所建议的,看起来您正在尝试处理JSON文档。我推荐这个 但是,如果转换非常简单,并且您不希望输入有太多变化,那么您可以自己操作字符串。一个简单的方法是这样做:
{"label":{"en":"Africa","de":"Afrika"},"description":{"en":"continent","de":"irdischer Kontinent"}}
var result = input.Replace(":{", " - ")
.Replace("},", Environment.NewLine)
.Replace("{", string.Empty)
.Replace("}", string.Empty);
您正在寻找JSON解析器。很好奇,为什么要这样做?这是一个JSON字符串,只需使用JSON解析器即可:是的,我可能需要解析大量wikidata以进行统计分析。也许将“\n”更改为Environment.NewLineJson.net就完美了。谢谢