目录

1.jsoneditor库下载地址:

2.下载并编译

(1).安装依赖

(2).编译

3.React集成jsoneditor

(1).引入jsoneditor

(2).在组件中使用jsoneditor


1.jsoneditor库下载地址:

JSON编辑器是一个基于web的工具,用于查看、编辑、格式化和验证JSON。它有各种模式,比如树编辑器、代码编辑器和纯文本编辑器。github地址:GitHub - josdejong/jsoneditor: A web-based tool to view, edit, format, and validate JSON

2.下载并编译

(1).安装依赖

yarn install

在安装过程中提示没有安装python2, 所以如果没有安装过python2的请自行查找资料进行安装,这里只对python系统环境变量的配置,进行说明

以python2为例进行说明(配置python3请使用相同的方式),首先进入python2安装目录,将python.exe,拷贝一份命名为python2.exe.

然后配置环境变量,在Path中添加以下两项:

然后继续执行yarn install,成功。

(2).编译

然后执行 yarn build 进行编译

3.React集成jsoneditor

(1).引入jsoneditor

将代码放置到public目录下。

index.html文件中导入jsoneditor.min.js和jsoneditor.min.css文件(当然有别的导入方式,例如js的方式,有兴趣的可以自行研究一下)

Note: 如果想要debug代码,请导入jsoneditor.js和jsoneditor.css文件,不要导入压缩混淆文件jsoneditor.min.js和jsoneditor.min.css文件

  <head><meta charset="utf-8" /><link rel="icon" href="%PUBLIC_URL%/favicon.ico" /><meta name="viewport" content="width=device-width, initial-scale=1" /><meta name="theme-color" content="#000000" /><metaname="description"content="Web site created using create-react-app"/><title>React App</title><link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" /><link rel="manifest" href="%PUBLIC_URL%/manifest.json" /><link href="jsonPlugin/jsoneditor.min.css" rel="stylesheet" type="text/css"><script src="jsonPlugin/jsoneditor.min.js"></script></head>

为了在所有react组件中都能够使用jsoneditor,在index.html文件中,定义工程全局变量 “var MyJSONEditor = JSONEditor;”,以便于在别的组件中,使用jsoneditor的功能

  <body><div id="root"></div><script>var MyJSONEditor = JSONEditor;</script></body>

(2).在组件中使用jsoneditor

我们使用的组件的名称叫 Example

定义组件中的全局变量jsoneditor(名字自己随便起),指向new的一个jsoneditor(jsoneditor = new window.MyJSONEditor(container, options)), 这样新new出来的jsoneditor就可以在组件中全局使用了。

var jsoneditor = {}; //定义组件中的全局变量,指向一个新创建的jsoneditor实例,组件中全局使用。
class Example extends Component {constructor(props) {super(props);jsoneditor = {};
...................................

下面就是具体怎样使用的代码

    componentDidMount() {const container = document.getElementById("jsoneditor") //jsoneditor容器const options = {mode: 'tree',onChangeJSON: (data)=>{console.log('JSONeditor:change:',data);}}//new一个jsoneditor实例jsoneditor = new window.MyJSONEditor(container, options)//设置theme 颜色为blue.container.querySelector('.jsoneditor-menu').style.backgroundColor = "rgb(18, 65, 145)";container.querySelector('.jsoneditor').style.border = "thin solid rgb(18, 65, 145)";//json数据const initialJson = {"Array": [1, 2, 3],"Boolean": true,"Null": null,"Number": 123,"Object": {"a": "b", "c": "d"},"MultiLevel":{"multi":{"e": "f","h": "h"}},"String": "Hello World","sensitive-data": {"sensitive1": "sensitive1","sensitive2": "sensitive2","sensitive3": "sensitive3"}}//jsoneditor加载json数据jsoneditor.set(initialJson)}//得到json数据,一般用于获取修改后的json数据onClick(){const updatedJson = jsoneditor.get();console.log("Debug: try to get the json data: " + updatedJson);}render() {return (<div><h1>Welcome!</h1><div><div style={{padding: '15px 0 0 20px',width: 'calc(100% - 55px)',height: this.props.editorHeight, 'overflow': 'auto'}}><div id="jsoneditor" className="jsoneditor-react-container" style={{width: '100%', height: '100%'}} /></div><Button onClick={this.onClick}>Get new Json</Button></div><Empty /></div>)}

看看效果:

用户可以修改json数据。

React 集成 jsoneditor 以对json数据进行展示和修改相关推荐

  1. json数据格式化展示出来

    今天有一个前公司的同事,请教我一个问题.他问我,怎么将一个JSON格式的数据,格式化以后展示出来.我想了想,于是乎写出了这个东西. <!DOCTYPE html> <html lan ...

  2. 数据展示html css,css实现json数据格式化展示.html

    json数据格式化 /* 方法1:设置textarea合适的宽高 */ #jsonTextarea { float: left; margin-right: 20px; width: 40%; hei ...

  3. 微信小程序(四)json数据循环展示

    html部分 <view class='list-head'>列表测试</view> <view class='list-box'><view class=' ...

  4. 前端实现json数据格式化展示

    1. 故事前景: 后端返回给前端一串json字符串,前端需要做格式化处理并将其美观地展示给用户. 2. 效果演示: 3. 实现代码: <!DOCTYPE html> <html la ...

  5. jQuery的Autocomplete插件的远程url取json数据的问题

    关于远程返回的json数据的展示,以前一样的代码,如果是本地写好的json串数据,插件显示就没有问题,一旦换成ulr方式读取一样的数据,插件就不能正常显示问题了. 今天偶然搜索资料找到一篇csdn上有 ...

  6. Dapper操作MySQL数据库获取JSON数据中文乱码

    在项目中利用Dapper将JSON数据存储到MySQL数据库,结果发现JSON数据中的中文乱码,特此记录,希望对存储JSON的童鞋能有所帮助,文中若有错误之处,还望批评指正. 为了引出最终问题出在什么 ...

  7. JS的jsoneditor,用来操作Json格式的界面;json-editor用来根据json数据生成界面

    1.jsoneditor https://github.com/josdejong/jsoneditor https://jsoneditoronline.org/ 效果如下: 2.json-edit ...

  8. React导入json数据

    本文提供两种方式,读者根据自己的需要进行选择. 1.第一种方式:直接import json文件. 这种方式依赖于 json-loader模块(npm install json-loader, http ...

  9. 创建Maven分布式前台系统架构,写出京动态导航,跨域返Json数据

    前台系统架构 分层的架构有什么好处: 有利于系统的维护,扩展. 分层的结构是按照功能细化,细化之后就能够分布式的部署. 灵活性 前台系统与服务层可以分离 开发团队可以分开,提高开发效率 缺点: 服务器 ...

  10. JSon数据查询---Jlinq

    LINQ,语言集成查询(Language INtegrated Query)是一组用于c#和Visual Basic语言的扩展.它允许编写C#或者Visual Basic代码以查询数据库相同的方式操作 ...

最新文章

  1. 西湖大学鞠峰组:环境微生物的宏基因组学实例与新发现
  2. warning C4800: 'int' : forcing value to bool 'true' or 'false' (performance warning)
  3. 使用FirefoxDriver时报错Make sure firefox is installed问题
  4. 【备忘】Oracle10g 创建、删除表空间、创建、授权用户
  5. springboot官网-pom.xml文件
  6. python中name没有定义_python中__name__的使用
  7. C++或C 实现AES ECB模式加密解密,支持官方验证
  8. uva 1637 Double Patience
  9. 四川绵阳:充分利用区块链等技术,为农民工证照办理提供线上便捷服务
  10. html网页使用js连接mysql_html下利用javascript连数据库
  11. 蓝色的网站商城后台通用管理模板——后台
  12. Linux偷偷“吃”了我的内存?
  13. linux中Oops信息的调试及栈回溯—Linux人都知道,这是好东西!
  14. Excel催化剂100+大主题功能梳理导读
  15. 【Verilog】parameter
  16. 数字签名,盲签名,环签名,群签名
  17. python数据分析师 前景_数据分析师是否有前途
  18. 微信小程序 基础 - 05 (wxml语法:动态数据绑定)
  19. 【Java书笔记】:《深入理解Java虚拟机:JVM高级特性与最佳实践(第3版)》第2部分-自动内存管理,第3部分-虚拟机执行子系统,第5部分-高效并发
  20. aws eks 快速启动和配置

热门文章

  1. 【SVN】SVN创建分支
  2. java json转map_Java 把json对象转成map键值对的方法
  3. 沈阳大学专升本计算机宿舍,沈阳大学宿舍怎么样 住宿条件好不好
  4. 北京计算机学校招生要求,北京小升初 16区采取电脑随机录取的入学途径及规则 2021家长一定要看...
  5. 减少 JPG 文件大小
  6. esp8266教程:GPIO输入输出模式
  7. office哪个版本最好用?都有哪些版本
  8. cad通过钢筋大样生成钢筋明细表插件_cad通过钢筋大样生成钢筋明细表插件_钢筋算量软件操作技巧汇总!!!...
  9. jmeter-模拟弱网测试
  10. 目标检测的图像特征提取之(三)Haar特征