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

  • andony5589

    andony5589

    7 Aralık 2011
  • DanceOn

    DanceOn

    6 Mayıs 2006
  • Jonah Penna

    Jonah Penna

    11 EYLÜL 2005