There is a class for deserializing json strings

  public class RootObject { public string id { get; set; } public string display_advertiser { get; set; } public object advertiser_id { get; set; } } 

In the program code, I deserialize the input json string into it

  List<RootObject> root = new List<RootObject>(); var item = new JavaScriptSerializer().Deserialize<RootObject>(str); root.Add(item) 

Now I want to run through the root elements and combine the data of each instance into a string with a separator ;

 for (int i = 0; i < root.Count; i++) { var data = string.Join(";",... а что писать тут?); } 

In general, it is not entirely clear how to convert an element of an array to a string.

  • redefine the ToString method on the RootObject class - Grundy
  • 2
    Show an example of a list of elements and text that should be obtained from this list. - VladD

1 answer 1

  public class RootObject { public string id { get; set; } public string display_advertiser { get; set; } public object advertiser_id { get; set; } public override string ToString() { return $"{id},{display_advertiser},{advertiser_id}"; } } ... var data = string.Join(";", root); 
  • 2
    Just specify the list. ToString() for each element will be called automatically. - andreycha
  • corrected, exactly, thank you - Mykhailo