V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
cxl008
V2EX  ›  Python

求教 json 解析

  •  
  •   cxl008 · Sep 4, 2014 · 4327 views
    This topic created in 4259 days ago, the information mentioned may be changed or developed.
    droidbox 里面 一段
    { "CryptoUsage": { "operation": "encryption", "algorithm": "AES/CBC/PKCS5Padding", "data": "{"model":"Full Android on Emulator","location":"","nettype":"3","manufacturer":"unknown","imei":"115732340242753","activetime":"1409818147","basebandversion":"no message","kernelversion":"2.6.29-gc497e41\nkroot@kennyroot #2\nThu Dec 8 15:07:43 PST 2011","osversion":"4.1.1","operator":"310260000000000","ip":"fe80::5054:ff:fe12:3456%eth0","pix":"320*480","deviceid":"0761AE5246580A7087A39BA0BA48BAA0"}" } }


    因为 data 后面 多了一对 引号 json.loads except 了。。。。有什么办法处理正确啊?
    16 replies    2014-09-05 10:05:17 +08:00
    keithellis
        1
    keithellis  
       Sep 4, 2014
    先格式化一遍 JSON 字符串。。。
    clino
        2
    clino  
       Sep 4, 2014
    这个就是错的吧,如果在json字符串中要有"那应该加转义符\吧?
    allenm
        3
    allenm  
       Sep 4, 2014
    这个 JSON 字符串本身就是错的。应该从源头着手,用 JSON 标准库来做序列化,尽力不要手工拼接,除非你非常了解 JSON 的规范,并且知道你在干什么。
    no13bus
        4
    no13bus  
       Sep 4, 2014
    试试demjson
    cxl008
        5
    cxl008  
    OP
       Sep 4, 2014
    @allenm 源头是没办法改了。得到就是这样的串。。。。
    cxl008
        6
    cxl008  
    OP
       Sep 4, 2014
    @keithellis 恕我愚钝,如何操作?
    cxl008
        7
    cxl008  
    OP
       Sep 4, 2014
    @no13bus 还是不好使
    keithellis
        8
    keithellis  
       Sep 4, 2014   ❤️ 1
    JSONRaw.replace('"data": "', '"data": ')
    JSONRaw.replace('"}" } }', '"} } }')
    cxl008
        9
    cxl008  
    OP
       Sep 4, 2014
    @keithellis 是个办法啊。。。。。
    wwlweihai
        10
    wwlweihai  
       Sep 4, 2014
    百度下 json格式化,然后你就能看到结构,一看就明白
    cxl008
        11
    cxl008  
    OP
       Sep 4, 2014
    @wwlweihai 这回答。。。需要关小黑屋啊。。。。。问题里面都说了 这个串错误的原因,不是不了解json结构,是问怎么好的处理方式。 百度是万能的就不来v2了。。。。
    wwlweihai
        12
    wwlweihai  
       Sep 4, 2014
    不好意思,解决不了。json,我没有仔细看过json串,
    dong3580
        13
    dong3580  
       Sep 4, 2014
    这个明显是json格式有问题的嘛,先把获取到的json个转换成正常的才行啊,
    binux
        14
    binux  
       Sep 4, 2014
    如果你用错误的方式用 JSON,人家都不知道你要表达什么,怎么给你解?
    lldld
        15
    lldld  
       Sep 5, 2014
    你都知道是多了一对引号了,还不能处理么?
    happywowwow
        16
    happywowwow  
       Sep 5, 2014
    怎么能容忍这串错误json的传给你
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2424 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 51ms · UTC 04:41 · PVG 12:41 · LAX 21:41 · JFK 00:41
    ♥ Do have faith in what you're doing.