首页 > 解决方案 > 如何在 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}

谢谢 >

标签: pythonhjson

解决方案


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.


推荐阅读