我们如何在React-Native中将HTML文件/元素转换为JSON格式

时间:2018-09-24 11:54:07

标签: html json react-native

使用react-native开发示例应用程序,我得到html格式的响应。如何在react-native中将html响应转换为JSON格式。

这正是我得到的答复

"content": "<!doctype html>\r\n<html>\r\n<head>\r\n<style>\r\n#ac-wrapper {\r\n    position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(255,255,255,.6); z-index: 1001;\r\n}\r\n.region{\r\n    color: #fff; font-weight: bold; text-transform: capitalize;\r\n}\r\n.city{\r\n    color: #fff;\r\n}\r\n.no-margin{\r\n    margin:0px;\r\n}\r\n#popup{\r\n    width: 555px; height: 230px; background: #0B6390; border: 1px solid #0B6390; box-shadow: #64686e 0px 0px 3px 3px;\r\n    -moz-box-shadow: #64686e 0px 0px 3px 3px; -webkit-box-shadow: #64686e 0px 0px 3px 3px; position: relative; top: 150px;\r\n}\r\n.button, .button:hover{\r\n    width:100%; background:#fff; color:#000 !important; font-weight: bold;\r\n}\r\n</style>\r\n</head>\r\n\r\n<body>\r\n<center>\r\n<div id=\"ac-wrapper\">\r\n  <div id=\"popup\">\r\n    <h2 class=\"region\">Select Your Region</h2>\r\n    </br>\r\n    <h3 class=\"city\" >Choose Your Nearest City</h3>\r\n    <br>\r\n      <div class=\"col-sm-6\">\r\n          <a href=\"{{store url=\"\"}}vizag\" target=\"_blank\">\r\n              <button class=\"button\">Visakhapatnam</button>\r\n           </a>             \r\n     </div>\r\n      <div class=\"col-sm-6\">\r\n          <a href=\"{{store url=\"\"}}hyd\" target=\"_blank\">\r\n              <button class=\"button\">Hyderabad</button>\r\n           </a>             \r\n     </div>\r\n  </div>\r\n</div>\r\n</center>\r\n\r\n<script type=\"text/javascript\">\r\nfunction PopUp(){\r\n        document.getElementById('ac-wrapper').style.display=\"none\"; \r\n}\r\n</script>\r\n</body>\r\n\r\n</html>"

1 个答案:

答案 0 :(得分:0)

您可以使用以下库:https://github.com/andrejewski/himalaya

import {parse} from 'himalaya'
const html = '<html/>' //your html goes here
const json = parse(html)
console.log(json)