È possibile utilizzare JSON.Net biblioteca. È possibile creare una classe di entità che si desidera convertire in JSON anziché utilizzare formattatore di stringhe.
per es.
public class Account
{
public string Email { get; set; }
public bool Active { get; set; }
public DateTime CreatedDate { get; set; }
public IList<string> Roles { get; set; }
}
Account account = new Account
{
Email = "[email protected]",
Active = true,
CreatedDate = new DateTime(2013, 1, 20, 0, 0, 0, DateTimeKind.Utc),
Roles = new List<string>
{
"User",
"Admin"
}
};
string json = JsonConvert.SerializeObject(account, Formatting.Indented);
Console.WriteLine(json);
uscita:
// {
// "Email": "[email protected]",
// "Active": true,
// "CreatedDate": "2013-01-20T00:00:00Z",
// "Roles": [
// "User",
// "Admin"
// ]
// }
Grazie questo sta lavorando bene ... –
Dovrebbe essere 'JsonConvert.SerializeObject (new {LongURL = LongURL});' però :) – ajgarn
@ajgarn Questo è corretta. Aggiustato. :) –