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

  • FRED

    FRED

    1 EKİM 2005
  • ICON

    ICON

    19 EKİM 2011
  • sinumatic

    sinumatic

    19 Aralık 2006