SORU
14 Aralık 2010, Salı


Nasıl bir JObject serisini .NET nesne

Ben mutlu Newtonsoft JSON librarykullanın. Örneğin bir JObject bir oluşturmak istiyorum .NET, bu durumda istisnai bir örnek (veya bir alt sınıfı olabilir) nesne

if (result is Exception)
    var jobjectInstance = JObject.FromObject(result);

şimdi kütüphane nesneyi JSON metin (string gibi) serisini biliyorum

// only works for text (string)
Exception exception = JsonConvert.DeserializeObject<Exception>(jsontext); 

ama ben ne arıyorum:

// now i do already have an JObject instance
Exception exception = jobjectInstance.????

Peki JSON metin JObject geri gitmek ve işlevsellik serisini kullanabiliyorum açıktır, ama tam tersi gibi geliyor bana.

CEVAP
31 AĞUSTOS 2012, Cuma


Buna göre post, şimdi çok daha iyi

// pick out one album
JObject jalbum = albums[0] as JObject;

// Copy to a static Album instance
Album album = jalbum.ToObject<Album>();

Belgeler: Convert JSON to a Type

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

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • michellefeng's channel

    michellefeng

    26 Kasım 2006
  • pleated-jeans

    pleated-jean

    6 HAZİRAN 2013
  • xXGAMERrs_Xx

    xXGAMERrs_Xx

    31 Temmuz 2014