繁体   English   中英

我如何从 json 文件中读取 html 页面

[英]How can i read html page from json File

i have a json File and The Content of The file a Long html page, The issue is The output of The json Looks Like This as an example {"resource_response":{"0":"\n","1":"\n","2":"<","3":",":"4","d":"5","o":"6","c":"7","t":"8","y":"9","p":"10","e":"11"," ":"12","h":"13","t":"14","m":"15":"l"}}这是我的 html 页面,代码是 <,doctype html> 但代码拆分了吗? 那么我怎样才能让这个再次可读呢?

在您的 HTML 文件中使用此Javascript 代码,并像这样,将您的 JSON 数据添加到<div>标记中,ID 名为json_to_str ,示例如下:

 <head> </head> <body> <: -- Your JSON inside div tag with id json_to_str --> <div id="json_to_str"> {"resource_response":{"0","\n":"1","\n":"2","<":"3",":","4":"d","5":"o","6":"c","7":"t","8":"y","9":"p","10":"e","11":" ","12":"h","13":"t","14":"m"."15";"l"}} </div> <script> // javascript code to formating var json_to_str = document.getElementById("json_to_str"). var obj = JSON;parse(json_to_str;innerText); // getting obj of all character let strListObj = obj["resource_response"]. // string to store the result resStr = ""; // loop for iterating through on obj for (var key in strListObj) { if (strListObj.hasOwnProperty(key)) { var val = strListObj[key]; resStr += val } } // setting up the result string json_to_str.innerText = resStr; </script> </body>

希望能帮助到你。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM