Skip to content
  • P
    Projects
  • G
    Groups
  • S
    Snippets
  • Help

xiaoqi / mp4giftconvert

  • This project
    • Loading...
  • Sign in
Go to a project
  • Project
  • Repository
  • Issues 0
  • Merge Requests 0
  • Pipelines
  • Wiki
  • Snippets
  • Members
  • Activity
  • Graph
  • Charts
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
  • Files
  • Commits
  • Branches
  • Tags
  • Contributors
  • Graph
  • Compare
  • Charts
Switch branch/tag
  • mp4giftconvert
  • gift_parser.py
Find file
BlameHistoryPermalink
  • xiaoqi's avatar
    修正了一个版本 · a9afabff
    xiaoqi committed 4 weeks ago
    a9afabff
gift_parser.py 885 Bytes
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
from dataclasses import dataclass, field
from typing import List, Optional

# 假设你已经有了json_data这个变量,它包含了你的JSON字符串
import json

@dataclass
class Gift:
    darkMd5: str
    darkRes: str
    gid: int
    md5: str
    resource: str
    weight: int
    zipMd5: Optional[str] = ""
    zipRes: Optional[str] = ""


@dataclass
class Response:
    msg: str
    code: int
    data: List[Gift]
    md5: str




def json_to_entity(json_str: str) -> Response:
    # 将JSON字符串解析成字典
    parsed_dict = json.loads(json_str)

    # 提取"data"部分并转换为Gift实例列表
    gifts = [Gift(**gift_data) for gift_data in parsed_dict['data']]

    # 创建Response实例
    response = Response(
        msg=parsed_dict['msg'],
        code=parsed_dict['code'],
        data=gifts,
        md5=parsed_dict['md5']
    )

    return response