Answer the question
In order to leave comments, you need to log in
How to format JSON into output like this (C#)?
Input
[{"markId":121,"markName":"VW","serieId":300,"serieName":"Multivan","generatedUrl":"category/tandemnyj-nasos-id345-3/vw-id121--2000"},{"markId":121,"markName":"VW","serieId":305,"serieName":"Touareg","generatedUrl":"category/tandemnyj-nasos-id345-3/vw-id121--2000"},{"markId":121,"markName":"VW","serieId":307,"serieName":"Transporter","generatedUrl":"category/tandemnyj-nasos-id345-3/vw-id121--2000"}]
Answer the question
In order to leave comments, you need to log in
using System.Text.Json;
var text = Console.ReadLine();
var jsonDocument = JsonDocument.Parse(text);
var elements = from obj in jsonDocument.RootElement.EnumerateArray()
let mark = obj.GetProperty("markName").GetString()
let serie = obj.GetProperty("serieName").GetString()
let name = $"{mark} {serie}"
select name;
var result = string.Join(", ", elements);
Console.WriteLine(result);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question