V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
kachni
V2EX  ›  问与答

python3bytes 对象如何转换为字典

  •  
  •   kachni · Feb 2, 2015 · 2846 views
    This topic created in 4104 days ago, the information mentioned may be changed or developed.

    使用百度翻译api获得的数据python默认编程bytes对象了,这样bytes->string->json还是字符串,怎么样才能直接获得或者转换为字典呢?
    https://gist.github.com/Ka-chanNi/6761c668f1ec745b9550
    输出
    输出

    4 replies    2015-02-03 00:03:53 +08:00
    kachni
        2
    kachni  
    OP
       Feb 2, 2015
    @aaaa007cn json.loads不是把json对象变成python对象吗?可我现在是想倒过来转化啊
    aaaa007cn
        3
    aaaa007cn  
       Feb 2, 2015
    从 gist 看
    sec_result = new_result.decode('ascii')
    new_result(bytes) → sec_result(str)
    json.loads 是 str → dict
    你不就是想“转换为字典”么

    所以你到底想干什么
    kachni
        4
    kachni  
    OP
       Feb 3, 2015
    @aaaa007cn 是我把之前的代码改错了,现在可以了,多谢
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5130 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 32ms · UTC 05:55 · PVG 13:55 · LAX 22:55 · JFK 01:55
    ♥ Do have faith in what you're doing.