python - 如何在 python (Pycharm) 中读取 Hjson 文件?
问题描述
我想知道如何在 python 中读取“.Hjson”文件?我已经获得了一个 Hjson 格式的数据集,并希望使用 Python 对其进行分析,例如获取 x 和 y 。数据如下所示:
Project:{ centerX:0, centerY:0, scaleX:0.37, scaleY:-0.21, angle:0 }
Tiles:[
{ x:-1.292007, y:0.9794083, width:0.2, height:0.2}
{ x:-1.413942, y:-1.083101, width:0.2, height:0.2}
{ x:1.430358, y:1.154297, width:0.2, height:0.2}
{ x:1.862622, y:0.1652414, width:0.2, height:0.2}
{ x:1.726217, y:-0.8780851, width:0.2, height:0.2}
{ x:0.572257, y:0.9339409, width:0.2, height:0.2}
{ x:1.188227, y:0.4919281, width:0.2, height:0.2}
{ x:0.05530262, y:0.6475933, width:0.2, height:0.2}
{ x:-0.8808339, y:0.4798487, width:0.2, height:0.2}
{ x:-0.3528011, y:0.1176641, width:0.2, height:0.2}
{ x:0.774766, y:-0.06418264, width:0.2, height:0.2}
{ x:-1.037972, y:-0.2158461, width:0.2, height:0.2}
{ x:-0.1206918, y:-0.6493511, width:0.2, height:0.2}
{ x:0.9421639, y:-0.5510759, width:0.2, height:0.2}
谢谢 >
解决方案
import hjson
def openHJSON():
deserializeFileName = 'yourfile.hjson'
with open(deserializeFileName) as deserializeFile:
deserializeObj = hjson.loads(deserializeFile.read())
for someObject in deserializeObj["someKey"]:
# Do it til you're satisfied.
推荐阅读
- python - 如何掩盖底图python上的计数图?
- linux - 编程中“原子性”的确切定义是什么?
- entity-framework - LINQ - 加入 3 个表并选择一个包含两个列表的项目
- java - Java:从 Play Framework 应用程序中使用 Spring WebFlux 应用程序
- html - 如何使 DIV 元素响应屏幕分辨率
- c - 在 C 中打印字节数组时处理神秘的输出
- discord.js - 在特定公会的特定频道中编辑消息 | 不和谐.js
- python - PyQt 使用向导和单选按钮
- python - Del 命令未正确执行 Pandas
- google-cloud-platform - ownCloud 10.0.7 连接数据库失败