Reputation: 6868
I am trying to create below response from dictionary:
['Employee1'] : List of skills
Code :
public class Skills
{
public string Skill {get;set;}
}
var skills=FetchSkills();
var dictionary = new Dictionary<string, List<Skills>>();
dictionary.Add('Employee1',skills);
Now i am trying to create below response:
'Employee1' =
{
{"skill":"skill1"},{"skill":"skill2"},{"skill":"skill3"}
}
I want skill property in camel case in my final response.
This is how i am trying to create response but not getting how to create expected response:
return Json(dictionary.Select
(
), JsonRequestBehavior.AllowGet);
Upvotes: 1
Views: 636
Reputation: 247223
Given class
public class Skills {
[JsonProperty("skill")]
public string Skill {get;set;}
}
and used like this
var skills=FetchSkills();
var dictionary = new Dictionary<string, List<Skills>>();
dictionary.Add('Employee1',skills);
return Json(dictionary, JsonRequestBehavior.AllowGet);
should produce
{
"Employee1":[
{"skill":"skill1"},{"skill":"skill2"},{"skill":"skill3"}
]
}
Upvotes: 1