recherche

Maison  >  Questions et réponses  >  le corps du texte

javascript - js中怎么判断一个字符串能否转成对象

比如一个函数

function some(param) {
    //判断param能否转成json对象
    //...
    return JSON.parse(param);
}

怎么判断呢

ringa_leeringa_lee2900 Il y a quelques jours495

répondre à tous(1)je répondrai

  • 大家讲道理

    大家讲道理2017-04-10 15:15:34

    try{
        a=JSON.parse(param);
    }catch(e){
        alert(e); //error in the above string(in this case,yes)!
    }
    

    répondre
    0
  • Annulerrépondre