SORU
28 Kasım 2010, Pazar


Nasıl bir değer json bir nesne olup olmadığını kontrol edebilir miyim?

Benim sunucu tarafı kodunu döndürür başarı ve bir dize üzerinde bir json nesnesi 'yanlış' hatası. bir değer Şimdi nasıl döndürülen değeri json bir nesne olup olmadığını kontrol edebilir miyim?

CEVAP
28 Kasım 2010, Pazar


bir WordPress kullanmak.() parseJSON türünde bir nesne döndürür "nesne" eğer dize JSON olsaydı, bu yüzden yalnızca sattığınız ile: türünü kontrol edin

var response=jQuery.parseJSON('response from server');
if(typeof response =='object')
{
  //It is JSON
}
else
{
  if(response ===false)
  {
     //the response was a string "false", parseJSON will convert it to boolean false
  }
  else
  {
    //the response was something else
  }
}

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

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • Official Android Tips

    Official And

    23 EYLÜL 2009
  • Chanre Joubert

    Chanre Joube

    27 Temmuz 2012
  • The Bad Tutorials

    The Bad Tuto

    6 EKİM 2009