Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Json formatted string to list

Tags:

json

string

c#

list

I have a string like this:

{"label":{"en":"Africa","de":"Afrika"},"description":{"en":"continent","de":"irdischer Kontinent"}}

Is possible convert to list like:

"label" - "en":"Africa","de":"Afrika"
"description" - "en":"continent","de":"irdischer Kontinent"

Thanks

like image 627
user2320490 Avatar asked May 18 '26 16:05

user2320490


1 Answers

As others have suggested, it looks like you're trying to process a JSON document. I recommend Json.NET for this.

However, you can manipulate your string by itself if the transformation is very simple and you don't expect much variation in your input. One easy way would be to do something like this:

var result = input.Replace(":{", " - ")
                  .Replace("},", Environment.NewLine)
                  .Replace("{", string.Empty)
                  .Replace("}", string.Empty);
like image 156
p.s.w.g Avatar answered May 20 '26 06:05

p.s.w.g