簡體   English   中英

將json轉換成python中的字典時出錯

[英]error in converting json to a dictionary in python

for i in products.iter():
    print i

這是我運行的代碼,輸出如下:

localhost:desktop siddharth$ python reader.py 
{u'sem3_id': u'1IngGhlIpoOGYCiMaEASSQ', u'cat_id': u'12151', u'updated_at': 1379589873, u'height': u'213.36', u'offers_total': 13, u'category': u'Inkjet Printers', u'price_currency': u'USD', u'sem3_help': u'To view image links for this product, please upgrade your plan.', u'width': u'281.94', u'sitedetails': [{u'sku': u'B00005AL05', u'latestoffers': [{u'price': u'366.99', u'shipping': u'19.98', u'seller': u'Buy4Less Now!', u'currency': u'USD', u'lastrecorded_at': 1379589800, u'firstrecorded_at': 1377106600, u'id': u'1BA5umTG80Gkg0oi40kiOu', u'condition': u'New'}, {u'price': u'379.96', u'shipping': u'12.49', u'seller': u'Battle Distribution, LLC', u'currency': u'USD', u'lastrecorded_at': 1379589800, u'firstrecorded_at': 1374975300, u'id': u'05cPhKOvouWkGc08sKaseq', u'condition': u'New'}, {u'price': u'99.99', u'shipping': u'12.49', u'seller': u'clabro', u'currency': u'USD', u'lastrecorded_at': 1379589800, u'firstrecorded_at': 1365164600, u'id': u'7aUtWYQlLkGuygGeWOgKWu', u'condition': u'Used - Very Good'}], u'name': u'amazon.com', u'url': u'http://www.amazon.com/dp/B00005AL05', u'offers_count': 13, u'recentoffers_count': 5}], u'price': u'366.99', u'gtins': [u'00033584113910'], u'ean': u'0033584113910', u'mpn': u'C408011', u'brand': u'Epson', u'geo': [u'usa'], u'manufacturer': u'Epson', u'name': u'Epson Stylus Photo 785EPX Inkjet Printer', u'created_at': 1347483414, u'upc': u'033584113910', u'length': u'264.16', u'model': u'C408011'}

我如何使它成為python字典?

我嘗試從上面使用的迭代器進行列表解析,然后執行json.loads(listcomprehension),但這給了我錯誤。

列表以[ ,開頭,但以)結尾。 將其更改為] ()用於元組。

>>> import json
>>> json.loads('[{"name":"same"}]')
[{u'name': u'same'}]

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM