You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

43 lines
1.0 KiB

import json
from dataclasses import dataclass
from typing import List
@dataclass
class SensorImg:
base64: str
def to_json(self) -> str:
"""将数据类序列化为 JSON 字符串"""
return json.dumps(self.__dict__, indent=4, default=lambda x: x.__dict__)
@classmethod
def from_json(cls, json_str: str) -> 'SensorImg':
"""从 JSON 字符串反序列化为数据类"""
data_dict = json.loads(json_str)
return cls(**data_dict)
@dataclass
class SensorData:
pos: str
x: float
y: float
def to_json(self) -> str:
"""将数据类序列化为 JSON 字符串"""
return json.dumps(self.__dict__, indent=4, default=lambda x: x.__dict__)
@classmethod
def from_json(cls, json_str: str) -> 'SensorData':
"""从 JSON 字符串反序列化为数据类"""
data_dict = json.loads(json_str)
return cls(**data_dict)
@dataclass
class AllSensorData:
data: List[SensorData]
time: str
@dataclass
class AllImg:
image: SensorImg
time: str