我开发这个返回一个WCF Web服务:
{
"allFormsResult": [
{
"FormId": 1,
"FormName": "Formulario 1"
},
{
"FormId": 2,
"FormName": "Formulario 2"
},
{
"FormId": 3,
"FormName": "Formulario 3"
}
]
}
这是代码:
public class RestServiceImpl : IRestServiceImpl
{
public List<FormContract> allForms()
{
List<FormContract> list = null;
using (var vAdmEntities = new ADMDatabase.ADMEntities())
{
list = new List<FormContract>();
foreach (var form in vAdmEntities.Form)
{
FormContract formC = new FormContract
{
FormName = form.name.Trim(),
FormId = form.formId
};
list.Add(formC);
}
}
return list;
}
}
我该怎么做才能生成它以这种方式?
[
{
"FormId": 1,
"FormName": "Formulario 1"
},
{
"FormId": 2,
"FormName": "Formulario 2"
},
{
"FormId": 3,
"FormName": "Formulario 3"
}
]