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

  • Karan Thakur

    Karan Thakur

    23 HAZİRAN 2010
  • Kyletiv7

    Kyletiv7

    28 Mayıs 2007
  • The Exploiteers

    The Exploite

    4 Ocak 2011