C
C#3y ago
JustiPhi

Issue with JSON Serialisation

When converting from object to json i need my list of object to be as follows "group": [{ "item": {}, "item": {} }] Instead I am getting "group": [{ "item": [ {}, {} ] }] How would I create my object to serialise it in the correct way? Thanks in advance
10 Replies
JustiPhi
JustiPhiOP3y ago
currently the group class looks like this
public class FilterGroup
{
public List<FilterItem> item { get; set; }
}
public class FilterGroup
{
public List<FilterItem> item { get; set; }
}
Jayy
Jayy3y ago
I mean... you declared item as a list of objects lol So it serialized to a json list
JustiPhi
JustiPhiOP3y ago
so i cant really make it serialise the correct way? without making a custom toJson method
Jayy
Jayy3y ago
Err, i mean if you don't want it to be a list don't make it a list It's doing it the correct way right now
JustiPhi
JustiPhiOP3y ago
but then how do i allow multiple
Jayy
Jayy3y ago
I mean... u use a list lol like ur doing Which will generate a json with a list This first example only allows one item So it doesn't allow multiple
JustiPhi
JustiPhiOP3y ago
which means i need a custom ToJson method for it i guess
Jayy
Jayy3y ago
No... You don't This is a weird question cuz you want a list but you want it to not be a list? Like that makes 0 sense
JustiPhi
JustiPhiOP3y ago
i may have been misreading the json havent been working with json in years yeah im stupid and i got it, thanks
Jayy
Jayy3y ago
👍
Want results from more Discord servers?
Add your server