web前端之json排查和格式变换

来源:互联网 发布:c语言编写图形 编辑:程序博客网 时间:2024/06/16 01:44

web前端之json排查和格式变换

json排查

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"><html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8"><title>Document</title><script type="text/javascript">function abc() { return {    "a":"1"    ,"b":"2"    ,"c":"3"}; };function sdTr(text, index) {    return (abc()[text] instanceof Array) ? abc()[text][index] : (abc()[text] || text);}function sTr(text) {    return sdTr(text, 0);}var json={    "a":"1"    ,"b":"2"    ,"c":"3"};var j=1;for (var i in json) {    console.log(j+"    "+sTr(json[i]));    j++;};</script></head><body></body></html>

json格式变换

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"><html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8"><title>Document</title><script type="text/javascript">window.onload=function(){    var json={        "a":"1"        ,"b":"2"        ,"c":"3"    };    var oBody=document.getElementById("Body");    for (var j in json) {        oBody.innerHTML+= ","+'"'+j+'"'+":"+'["'+json[j]+'"]'+"";    };    /*json变换成:json={"a":["1"],"b":["2"],"c":["3"]};*/};</script></head><body id="Body"></body></html>
1 0
原创粉丝点击