js中怎么判断一个字符串能否转成对象?
phpcn_u233
phpcn_u233 2017-02-27 13:39:30
0
2
2032

比如一个函数

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

怎么判断呢

phpcn_u233
phpcn_u233

reply all (2)
数据分析师

How to determine whether a string can be converted into an object in js? -PHP Chinese website Q&A-How to determine whether a string can be converted into an object in js? -PHP Chinese website Q&A

Let’s take a look and learn.

    阿神

    这样

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


      Latest Downloads
      More>
      Web Effects
      Website Source Code
      Website Materials
      Front End Template
      About us Disclaimer Sitemap
      php.cn:Public welfare online PHP training,Help PHP learners grow quickly!