#SVG to JSON
A method to convert a string of SVG to JSON data, and optionally render statistics.
#Usage
Create a new instance, provide `svg` string and optionally pass in `options`.
```js
var svg_json = new SVGToJSON(svg[, options]);
```
#API
##Object.json
`SVGToJSON()` returns an object. `OBJ.json` is the primary JSON data. It is an array of all SVG tags.
```js
var svg_json = new SVGToJSON(svg);
svg_json = {
json: [...]
}
```
##Object.json[i]
Each tag in `Object.json` has four values.
```js
var first_tag = svg_json.json[0];
first_tag = {
attrs: {
"height": "600",
"viewBox": "0 0 800 600",
"width": "800",
"xmlns": "http://www.w3.org/2000/svg",
"xmlns:xlink": "http://www.w3.org/1999/xlink"
},
name: "svg",
pos: 0,
type: "open"
}
```
###`attrs` (object)
Key-value pairs for each attribute on the tag.
###`name` (string)
The tag name.
###`pos` (integer)
The tab position of the tag.
###`type` (string)
The type of tag. `open`, `close`, or `closeself`.
##Object.stats (Object)
If stats are requested, `SVGToJSON` additionally returns `OBJ.stats` object. `OBJ.stats` contains counts for `attributes` and `elements`.
```js
"stats": {
"attributes": {
"height": 1,
"viewBox": 1,
"width": 1,
"xmlns": 1,
"xmlns:xlink": 1
},
"elements": {
"svg": 1
}
}
```
没有合适的资源?快使用搜索试试~ 我知道了~
svg-to-json:将SVG字符串转换为JSON
共4个文件
js:1个
html:1个
md:1个
需积分: 50 14 下载量 133 浏览量
2021-05-15
21:18:49
上传
评论 1
收藏 3KB ZIP 举报
温馨提示
#SVG到JSON一种将SVG字符串转换为JSON数据并可选地呈现统计信息的方法。 #Usage创建新实例,提供svg字符串,还可以选择传入options 。 var svg_json = new SVGToJSON ( svg [ , options ] ) ; #API ## Object.json SVGToJSON()返回一个对象。 OBJ.json是主要的JSON数据。 它是所有SVG标签的数组。 var svg_json = new SVGToJSON ( svg ) ; svg_json = { json : [ ... ] } ## Object.json [I]中的每个标签Object.json有四个值。 var first_tag = svg_json . json [ 0 ] ; first_tag = { attrs : { "h
资源推荐
资源详情
资源评论
收起资源包目录
svg-to-json-master.zip (4个子文件)
svg-to-json-master
index.html 473B
README.md 1KB
.gitignore 0B
svg-to-json.js 3KB
共 4 条
- 1
资源评论
Demeyi-邓子
- 粉丝: 22
- 资源: 4533
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功