首页新闻找找看学习计划

xml转换格式

0
悬赏园豆:50 [已解决问题] 解决于 2019-09-26 11:43

json文件格式如何转为pointData: [
{name: 'point-0001', x: 5000, y: 1500},
{name: 'point-0002', x: 5000, y: 10000},
{name: 'point-0004', x: 10000, y: 5000},
{name: 'point-0005', x: 15000, y: 10000},
{name: 'point-0006', x: 15000, y: 5000},
{name: 'point-0007', x: 20000, y: 10000},
{name: 'point-0008', x: 20000, y: 1500},
{name: 'point-0009', x: 5000, y: 15000},
{name: 'point-0010', x: 5000, y: 20000},
{name: 'point-0011', x: 10000, y: 15000},
{name: 'point-0012', x: 15000, y: 15000},
{name: 'point-0013', x: 20000, y: 15000},
{name: 'point-0014', x: 25000, y: 10000},
{name: 'point-0015', x: 25000, y: 15000},
{name: 'point-0016', x: 30000, y: 10000},
{name: 'point-0017', x: 30000, y: 5000},
{name: 'point-0018', x: 30000, y: 15000},
{name: 'point-0019', x: 35000, y: 10000},
{name: 'point-0020', x: 35000, y: 5000},
{name: 'point-0021', x: 35000, y: 15000},
{name: 'point-0022', x: 25000, y: 20000},
{name: 'point-0023', x: 35000, y: 20000},
{name: 'point-0024', x: 45000, y: 25000},
{name: 'point-0025', x: 10000, y: 10000},],

或者是xml文件格式如何转为

pointData: [
{name: 'point-0001', x: 5000, y: 1500},
{name: 'point-0002', x: 5000, y: 10000},
{name: 'point-0004', x: 10000, y: 5000},
{name: 'point-0005', x: 15000, y: 10000},
{name: 'point-0006', x: 15000, y: 5000},
{name: 'point-0007', x: 20000, y: 10000},
{name: 'point-0008', x: 20000, y: 1500},
{name: 'point-0009', x: 5000, y: 15000},
{name: 'point-0010', x: 5000, y: 20000},
{name: 'point-0011', x: 10000, y: 15000},
{name: 'point-0012', x: 15000, y: 15000},
{name: 'point-0013', x: 20000, y: 15000},
{name: 'point-0014', x: 25000, y: 10000},
{name: 'point-0015', x: 25000, y: 15000},
{name: 'point-0016', x: 30000, y: 10000},
{name: 'point-0017', x: 30000, y: 5000},
{name: 'point-0018', x: 30000, y: 15000},
{name: 'point-0019', x: 35000, y: 10000},
{name: 'point-0020', x: 35000, y: 5000},
{name: 'point-0021', x: 35000, y: 15000},
{name: 'point-0022', x: 25000, y: 20000},
{name: 'point-0023', x: 35000, y: 20000},
{name: 'point-0024', x: 45000, y: 25000},
{name: 'point-0025', x: 10000, y: 10000},],

冻死了开发的主页 冻死了开发 | 初学一级 | 园豆:105
提问于:2019-08-22 11:08
< >
分享
最佳答案
0
import json
import codecs
from xmltodict import parse

# json文件
file = codecs.open('test.json', 'r', 'utf-8').read()
data = json.loads(file)
print(data)

# xml 转 dict
file = codecs.open('test.xml', 'r', 'utf-8').read()
data = parse(file)
print(data)
收获园豆:50
Masako | 小虾三级 |园豆:1629 | 2019-08-23 14:41
其他回答(2)
0

python的话可以用json.load(文件句柄)直接导入,比如文件名是a.json实例代码如下
import json
with open('a.json') as fp:
json.load(fp)

水墨的心 | 园豆:361 (菜鸟二级) | 2019-08-22 11:50

如果是xml格式怎麽轉換

支持(0) 反对(0) 冻死了开发 | 园豆:105 (初学一级) | 2019-08-22 13:38

如何打开呢

支持(0) 反对(0) 冻死了开发 | 园豆:105 (初学一级) | 2019-08-22 14:06

@冻死了开发: https://blog.csdn.net/chinabestchina/article/details/78220422

支持(0) 反对(0) 水墨的心 | 园豆:361 (菜鸟二级) | 2019-08-22 14:55

@水墨的心: 在吗,可以加个微信吗

支持(0) 反对(0) 冻死了开发 | 园豆:105 (初学一级) | 2019-08-22 15:08

@水墨的心: 想请你帮个忙

支持(0) 反对(0) 冻死了开发 | 园豆:105 (初学一级) | 2019-08-22 15:08

@水墨的心: 我是想用什么方法能使一个xml文件转换成下面这样的,当然xml文件里有很多用不到的,下面这些是提炼出来的pointData: [
{name: 'point-0001', x: 5000, y: 1500},
{name: 'point-0002', x: 5000, y: 10000},
{name: 'point-0004', x: 10000, y: 5000},
{name: 'point-0005', x: 15000, y: 10000},
{name: 'point-0006', x: 15000, y: 5000},
{name: 'point-0007', x: 20000, y: 10000},
{name: 'point-0008', x: 20000, y: 1500},
{name: 'point-0009', x: 5000, y: 15000},
{name: 'point-0010', x: 5000, y: 20000},
{name: 'point-0011', x: 10000, y: 15000},
{name: 'point-0012', x: 15000, y: 15000},
{name: 'point-0013', x: 20000, y: 15000},
{name: 'point-0014', x: 25000, y: 10000},
{name: 'point-0015', x: 25000, y: 15000},
{name: 'point-0016', x: 30000, y: 10000},
{name: 'point-0017', x: 30000, y: 5000},
{name: 'point-0018', x: 30000, y: 15000},
{name: 'point-0019', x: 35000, y: 10000},
{name: 'point-0020', x: 35000, y: 5000},
{name: 'point-0021', x: 35000, y: 15000},
{name: 'point-0022', x: 25000, y: 20000},
{name: 'point-0023', x: 35000, y: 20000},
{name: 'point-0024', x: 45000, y: 25000},
{name: 'point-0025', x: 10000, y: 10000},],

支持(0) 反对(0) 冻死了开发 | 园豆:105 (初学一级) | 2019-08-22 15:13
0

->反序列化到对象->序列化到xml

没有其他解,至于第一步对象你可以用通用的,也可以写不通用的,module很多方法也有很多。

花飘水流兮 | 园豆:10177 (专家六级) | 2019-08-22 14:08

大神,我还是没听明白,方便花点时间给下具体的实现吗

支持(0) 反对(0) 冻死了开发 | 园豆:105 (初学一级) | 2019-08-22 14:11

方便加个微信吗大哥

支持(0) 反对(0) 冻死了开发 | 园豆:105 (初学一级) | 2019-08-22 14:13

帮帮忙,急需,以后要是能帮到你的地方,义不容辞

支持(0) 反对(0) 冻死了开发 | 园豆:105 (初学一级) | 2019-08-22 14:14
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册