Convert a list to JSON from a table


I am trying to convert a list to a json string. The json is generating fine, but when I try to generate an array within the JSON it won't format properly.

My list is generated

List<string> invoicesList = new List<string>();

        foreach (var invoice in theInvoices)
            invoicesList.Add(String.Format("{0:c}", invoice.GrandTotal));

Then I add it to the JSON

var info = new MobileAPIHelper.ClientPayrollInfo
            GrossWages = String.Format("{0:c}", GrossWages),
            InvoiceTotal = String.Format("{0:c}", invoiceTotal),
            InvoiceDate = FieldTranslation.ToShortDate(invoiceDate.ToString()),
            InvoiceList = invoicesList.ToArray()


The output ends up just being a long JSON string with everything from the list


What I can't figure out is how to get the list / json to format that invoicelist like so:


invoicesList is not a list of an object that contains those values, it's a list of strings. You need to make a class that acts as a container for

String.Format("{0:c}", invoice.GrandTotal);

these fields. Make invoicesList a list of that class, then parse it to json. You're adding raw strings.