簡體   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