python题目:把JSON字符串里面的数据进行替换【杭州多测师_王sir】

name ,时间戳,value这三个值要变

 

"tags":[
{
"values":[
{
"value": 43.6525,
"quality": 192,
"timestamp": 00
}
],
"name": "/system/Template_2/Instance_8/system/Property_10",
“type”: 12
}
]
}

 

import random
import os
import json

def generate_data():
    data = []
    for i in range(10):
        value = random.uniform(0, 100)  # 生成一个随机的value值
        timestamp = random.randint(0, 100)  # 生成一个随机的timestamp值
        name = "/system/Template_2/Instance_8/system/Property_" + str(random.randint(0, 9))  # 生成一个随机的name值
        data.append({"tags":[
            {
                "values":[
                {
                    "value": value,
                    "quality": 192,
                    "timestamp":timestamp,
                }
                ],
                "name":name,
                "type": 12
                }
                ]
        })
        o = open(os.getcwd() + "//" + "test" + str(i) + ".json", "w")
        o.writelines(json.dumps(data))

    return data

data = generate_data()
print(data)

posted @ 2023-11-02 12:08  多测师_树哥  阅读(95)  评论(0编辑  收藏  举报