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

  • SRT Photoshop Tutorials

    SRT Photosho

    19 Aralık 2012
  • vgeller1

    vgeller1

    22 Kasım 2009
  • Willie D.

    Willie D.

    16 Aralık 2006