C# JSON - Serializing Objects depending on conditions -
C# JSON - Serializing Objects depending on conditions -
i have on list of strings represent selected users.
i want serialize json in 1 of properties selected. true if user in list , false if not.
right have this:
viewbag.json = jsonconvert.serializeobject(new { utilizadores = db.utilizador.select(u => new { id = u.id, nome = u.nome, info = u.nummecanografico, selected = false }) });
example final result:
i want this, imagina user 1 , 2 in list. , have 4 users total.
utilizadores = [id:1, nome: user1, selected: true],[id:2, nome: user2, selected: true],[id:3, nome: user3, selected: false],[id:4, nome: user4, selected: false]
something this.
right don't see how can status here. can shed light?
i interpreted question in means "you have list
of selected users, json property selected
true if user in list"
ilist<string> selectedusers = ... //the list of selected usernames viewbag.json = jsonconvert.serializeobject(new { utilizadores = db.utilizador.select(u => new { id = u.id, nome = u.nome, info = u.nummecanografico, selected = selectedusers.contains(u.nome) }) });
c# json
Comments
Post a Comment