微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

使用SimpleJSON的简单Json解码-Python

如何解决使用SimpleJSON的简单Json解码-Python

| 香港专业教育学院刚刚开始学习python,而我正在使用Google Api进行尝试。但是我碰上一堵墙,试图用simplejson解析JSON。 我该如何从下面的混乱中获取单一价值(即产品或品牌领域)
{\'currentItemCount\': 25,\'etag\': \'\"izYJutfqR9tRDg1H4X3fGx1UiCI/hqqZ6pMwV1-CEu5NSqfJO0Ix-gs\"\',\'id\': \'tag:google.com,2010:shopping/products\',\'items\': [{\'id\': \'tag:google.com,2010:shopping/products/1196682/8186421160532506003\',\'kind\': \'shopping#product\',\'product\': {\'author\': {\'accountId\': \'1196682\',\'name\': \"Dillard\'s\"},\'brand\': \'Merrell\',\'condition\': \'new\',\'country\': \'US\',\'creationTime\': \'2011-03-10T08:11:08.000Z\',\'description\': u\'Merrell\\\'s \"Trail glove\" barefoot running shoe lets your feet follow their natural i$
                        \'googleId\': \'8186421160532506003\',\'gtin\': \'00797240569847\',\'images\': [{\'link\': \'http://dimg.dillards.com/is/image/DillardsZoom/03528718_zi_amazon?$product$\'}],\'inventories\': [{\'availability\': \'inStock\',\'channel\': \'online\',\'currency\': \'USD\',\'price\': 110.0}],\'language\': \'en\',\'link\': \'http://www.dillards.com/product/Merrell-Mens-Trail-glove-Barefoot-Running-Shoes_301_-1_301_5$
                        \'modificationTime\': \'2011-05-25T07:42:51.000Z\',\'title\': \'Merrell Men\\\'s \"Trail glove\" Barefoot Running Shoes\'},\'selfLink\': \'https://www.googleapis.com/shopping/search/v1/public/products/1196682/gid/8186421160532506003?alt=js$
    

解决方法

        您在问题中粘贴的JSON无效。但是,当您修复该问题后,这就是使用simplejson的方法:
    import simplejson as json
    your_response_body = \'[\"foo\",{\"bar\":[\"baz\",null,1.0,2]}]\'
    obj = json.loads(your_response_body)
    print(obj[1][\'bar\'])
以及文档的链接。     

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。