json字符串转数组

   后端传到前段的格式是这样的model.addAttribute("newsTagList", JSON.toJSON(list));

   将一个list转换为了json字符串

   前段我要把获取到的数据展示出来,这里有时候不转换为数组也可以用

   在for循环这个list之前,建议把返回的json字符串先转换为数组,这里我用最简单的方法,网上还有几种方法的:

   var themes;

   if("string"===typeof list ){

      themes=JSON.parse(list);

   }else{

      themes=list;

   }

 

猜你喜欢

转载自danstart.iteye.com/blog/2325723
今日推荐