Heim  >  Fragen und Antworten  >  Hauptteil

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

比如一个函数

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

怎么判断呢

phpcn_u233phpcn_u2332791 Tage vor2079

Antworte allen(2)Ich werde antworten

  • 数据分析师

    数据分析师2017-10-01 00:33:11

    js中怎么判断一个字符串能否转成对象?-PHP中文网问答-js中怎么判断一个字符串能否转成对象?-PHP中文网问答

    围观一下哦,学习一下。

    Antwort
    0
  • 阿神

    阿神2017-02-27 13:40:00

    这样

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


    Antwort
    0
  • StornierenAntwort