Generieren Sie ein JSON-Array mit WCF

Ich entwickle einen WCF-Webdienst, der Folgendes zurückgibt:

<code>{
    "allFormsResult": [
        {
            "FormId": 1,
            "FormName": "Formulario 1"
        },
        {
            "FormId": 2,
            "FormName": "Formulario 2"
        },
        {
            "FormId": 3,
            "FormName": "Formulario 3"
        }
    ]
}
</code>

Dies ist der Code:

<code>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;
        }
    }
</code>

Wie kann ich es auf diese Weise erzeugen?

<code>[
    {
        "FormId": 1,
        "FormName": "Formulario 1"
    },
    {
        "FormId": 2,
        "FormName": "Formulario 2"
    },
    {
        "FormId": 3,
        "FormName": "Formulario 3"
    }
]
</code>

Antworten auf die Frage(2)

Ihre Antwort auf die Frage