SORU
29 HAZİRAN 2009, PAZARTESİ


C JSON dize oluşturma#

Ben sadece XmlWriter geri, bir HTTP yanıtı göndermek için bazı XML oluşturmak için kullanılır. Nasıl bir JSON dize oluşturmak istiyorsunuz. Sadece JSON dize oluşturmak için bir stringbuilder kullanmak istiyorsunuz sanırım ve onlara yanıt olarak JSON formatında?

CEVAP
29 EYLÜL 2012, CUMARTESİ


Newtonsoft.Json kullanarak çok daha kolay hale getirir:

Product product = new Product();
product.Name = "Apple";
product.Expiry = new DateTime(2008, 12, 28);
product.Price = 3.99M;
product.Sizes = new string[] { "Small", "Medium", "Large" };

string json = JsonConvert.SerializeObject(product);

Belgeleri:Serializing and Deserializing JSON

Bunu Paylaş:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • ChannelRichard

    ChannelRicha

    7 Kasım 2008
  • FOSDEM

    FOSDEM

    13 Ocak 2009
  • Majestic Casual

    Majestic Cas

    28 NİSAN 2012