如何在python(Pycharm)中读取Hjson文件?

2024-05-12 23:28:39 发布

您现在位置:Python中文网/ 问答频道 /正文

我想知道如何在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}

谢谢>


Tags: 文件数据gtproject格式widthtilesheight
1条回答
网友
1楼 · 发布于 2024-05-12 23:28:39

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.

相关问题 更多 >