I am trying to generate the following json with JSON.Net but it is adding alot of extra square brackets with what should I do
Needed Json
{
"addUser": {
"idCard": "xxx",
"firstName": "xxx",
"surname": "Muscat",
"isActive": true,
"titleDesc": "xx",
"genderDesc": "Female",
"emailAddress":"",
"mobileNumber":"",
"telephoneNumber":"",
"dob":""
}
}
C# code
var obj = new JObject();
obj.Add(
new JProperty("addUser",
new JArray(
new JObject(
new JProperty("idCard", doct.First().idCard.PadLeft(8, '0')),
new JProperty ("firstName", det.First().PersonName),
new JProperty("surname", det.First().PersonSurname),
new JProperty("isActive", true),
new JProperty("titleDesc", ""),
new JProperty("genderDesc", det.First().PersonGenderDesc),
new JProperty("emailAddress", ""),
new JProperty("mobileNumber", ""),
new JProperty("telephoneNumber", ""),
new JProperty("dob", det.First().PersonBirthDate)
))));
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…