github thriftpy2

import thriftpy2.protocol.json as proto

def test_struct_to_json():
    obj = TItem(id=13, phones=["5234", "12346456"])
    json = proto.struct_to_json(obj)
    # 返回dict类型,str(json)转字符串
    assert {"id": 13, "phones": ["5234", "12346456"]} == json

def test_struct_to_obj():
    json = {"id": 13, "phones": ["5234", "12346456"]}
    obj = TItem()

    obj = proto.struct_to_obj(json, obj)

    assert obj.id == 13 and obj.phones == ["5234", "12346456"]

相关文章:

  • 2022-12-23
  • 2021-06-24
  • 2022-12-23
  • 2021-09-05
  • 2021-09-26
  • 2022-12-23
  • 2021-06-12
  • 2021-09-28
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-27
  • 2022-02-14
  • 2022-12-23
  • 2022-01-19
相关资源
相似解决方案