首页 > 网站 > WEB开发 > 正文

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

2024-04-27 15:15:59
字体:
来源:转载
供稿:网友

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>
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表