2
我開發返回此一個WCF Web服務:生成JSON陣列WCF
{
"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"
}
]
不確定,但嘗試返回'FormContract []'而不是'List'。 –
2012-04-09 13:30:18
不,它不起作用。 – VansFannel 2012-04-09 13:34:28