Home > php教程 > PHP开发 > Summary of methods for converting json format strings into javascript objects or arrays

Summary of methods for converting json format strings into javascript objects or arrays

高洛峰
Release: 2016-12-08 09:45:31
Original
1345 people have browsed it

The first one

JSON.parse(jsonString)

The second one

eval("("+jsonString+")")

The third one

var obj=(function ToJSON(o){
 if(typeof(o)=="string")try{return new Function("return "+o)();}catch(e){return null;}
})("[{name:'zhangsan',age:'24'},{name:'lisi',age:'30'},{name:'wangwu',age:'16'},{name:'tianqi',age:'7'}]");
for(var b in obj)alert(obj[b].name);
Copy after login


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template