首页 > 解决方案 > 我想从 python 中的 JSON 文件中获取一个随机对象

问题描述

只想要一个来自 JSON 的随机对象

标签: pythonjson

解决方案


import json

#import json file
filter = "JSON file (*.json)|*.json|All Files (*.*)|*.*||"
filename = rs.OpenFileName("Open JSON File", filter)

#Read JSON data into the datastore variable
if filename:
    with open(filename, 'r') as f:
        datastore = json.load(f)
Random.choice(datastore)

我希望它有效


推荐阅读