I was sending to a customer a list of 1 millions FOO
in json.
public class FOO
{
public string Foo, Name, Call, Loc, ID;
public double Long, Lat;
public string[] Adr, OpenningHours;
}
But the customer ask me for a specific output as it will reduce the data size:
Remove the Property name, join the address, and flattern that list their will always be 7 day in a week. Like:
[
[
"ag",
99.0000000,
9.0000000,
"FOO-FOO BAR",
"ADR1|ADR2|ADR3|ADR4",
"0101",
"07:30-12:00,12:00-19:30",
"07:30-12:00,12:00-19:30",
"07:30-12:00,12:00-19:30",
"07:30-12:00,12:00-19:30",
"07:30-12:00,12:00-19:30",
"07:30-13:00,",
",",
"07H30",
"FOO BAR"
],
]
I have no issue with the with the Address join or the flatern OpenningHours. Using:
public class ItemMapper
{
public string Foo, Name, Adr, ID, Call, Loc,
w1, w2, w3, w4, w5, w6, w7;
public double Long, Lat;
}
return
new ItemMapper
{
Foo = this.Foo,
// [...]
Adr = string.Join("|", this.Adr),
w1 = this.OpenningHours[0],
// [...]
w7= this.OpenningHours[6]
};
Is there a proper way to do that without pure string manipulation Replace etc?
The serialisation of a List give a bad result, that I fix with a compilled regex remplace :
[
{ <-- Not a []
"PopertyName":"PropertyValue", <-- Poperty Name, and :
// ..
"PopertyName":"PropertyValue",
},
]