Python从请求打印json数据
我一直在琢磨为什么它不打印我需要的json内容。有人知道我做错了什么吗 这是字典Python从请求打印json数据,python,json,python-requests,Python,Json,Python Requests,我一直在琢磨为什么它不打印我需要的json内容。有人知道我做错了什么吗 这是字典 > "listinginfo": { > "438309609514180554": { > "listingid": "438309609514180554", > "price": 35, > "fee": 4, > "publisher_fee_app": 730, > "publisher_fee_
> "listinginfo": {
> "438309609514180554": {
> "listingid": "438309609514180554",
> "price": 35,
> "fee": 4,
> "publisher_fee_app": 730,
> "publisher_fee_percent": "0.10000000149011612",
> "currencyid": "2003",
> "steam_fee": 1,
> "publisher_fee": 3,
> "converted_price": 50,
> "converted_fee": 7,
> "converted_currencyid": "2020",
> "converted_steam_fee": 2,
> "converted_publisher_fee": 5,
> "converted_price_per_unit": 50,
> "converted_fee_per_unit": 7,
> "converted_steam_fee_per_unit": 2,
> "converted_publisher_fee_per_unit": 5,
> "asset": {
> "currency": 0,
> "appid": 730,
> "contextid": "2",
> "id": "1579403640",
> "amount": "1",
> "market_actions": [
> {
代码+我需要要打印的键的值:
while 1:
r = requests.get(url, headers=headers)
listingInfoStr = r.content
result= ujson.loads(listingInfoStr)
listingInfoJson= result['listinginfo']
for listingdata in listingInfoJson:
print listingdata.get('listingId')
print listingdata.get('subTotal')
print listingdata.get('feeAmount')
print listingdata.get('totalPrice')
time.sleep(10)
感谢您抽出时间。您可以使用方法获取解析的JSON:
r = requests.get(url, headers=headers)
listingInfoJson = r.json()['listinginfo']
您可以使用方法获取解析的JSON:
r = requests.get(url, headers=headers)
listingInfoJson = r.json()['listinginfo']
您可以使用方法获取解析的JSON:
r = requests.get(url, headers=headers)
listingInfoJson = r.json()['listinginfo']
您可以使用方法获取解析的JSON:
r = requests.get(url, headers=headers)
listingInfoJson = r.json()['listinginfo']
我运行了您的代码,它看起来像ListingInfo JSON作为dict而不是列表返回。所以当你在上面迭代的时候,它只是在拉关键点 您正在对unicode对象调用.get方法,这将为您提供AttributeError。您可以以多种方式运行此代码:
for listingdata in listingInfoJson:
print listingInfoJson[listingdata].get('listingid')
print listingInfoJson[listingdata].get('subTotal')
print listingInfoJson[listingdata].get('feeAmount')
print listingInfoJson[listingdata].get('totalPrice')
或更好的方式(编辑评论):
我还要检查你的键值,
listingId
应该是listingId
我运行了你的代码,它看起来像listingInfoJson以dict而不是列表的形式返回。所以当你在上面迭代的时候,它只是在拉关键点
您正在对unicode对象调用.get方法,这将为您提供AttributeError。您可以以多种方式运行此代码:
for listingdata in listingInfoJson:
print listingInfoJson[listingdata].get('listingid')
print listingInfoJson[listingdata].get('subTotal')
print listingInfoJson[listingdata].get('feeAmount')
print listingInfoJson[listingdata].get('totalPrice')
或更好的方式(编辑评论):
我还要检查你的键值,
listingId
应该是listingId
我运行了你的代码,它看起来像listingInfoJson以dict而不是列表的形式返回。所以当你在上面迭代的时候,它只是在拉关键点
您正在对unicode对象调用.get方法,这将为您提供AttributeError。您可以以多种方式运行此代码:
for listingdata in listingInfoJson:
print listingInfoJson[listingdata].get('listingid')
print listingInfoJson[listingdata].get('subTotal')
print listingInfoJson[listingdata].get('feeAmount')
print listingInfoJson[listingdata].get('totalPrice')
或更好的方式(编辑评论):
我还要检查你的键值,
listingId
应该是listingId
我运行了你的代码,它看起来像listingInfoJson以dict而不是列表的形式返回。所以当你在上面迭代的时候,它只是在拉关键点
您正在对unicode对象调用.get方法,这将为您提供AttributeError。您可以以多种方式运行此代码:
for listingdata in listingInfoJson:
print listingInfoJson[listingdata].get('listingid')
print listingInfoJson[listingdata].get('subTotal')
print listingInfoJson[listingdata].get('feeAmount')
print listingInfoJson[listingdata].get('totalPrice')
或更好的方式(编辑评论):
我还要检查你的键值,
listingId
应该是listingId
请注意,listingInfoJson
实际上是一个Python dict,而不是JSON字符串。对不起,我不想使用ujson之外的任何其他JSON解析器。请注意,listingInfoJson
实际上是一个Python dict,不是JSON字符串。我不想使用ujson以外的任何其他JSON解析器,对不起。请注意,listingInfoJson
实际上是一个Python dict,而不是JSON字符串。我不想使用ujson以外的任何其他JSON解析器,对不起。请注意,listingInfoJson
实际上是一个Python dict,不是JSON字符串。对不起,我不想使用ujson以外的任何其他JSON解析器。因为listingInfoJson不可编辑?这只是一个命令,因为listingInfoJson不可编辑?这只是一个命令,因为listingInfoJson不可编辑?这只是一个命令,因为listingInfoJson不可编辑?只是口述而已谢谢,成功了!我更喜欢你刚才向我展示的“data.iteritems()”方式,我将对此进行更多的研究,再次感谢。想问你,目前“for”语句打印值,是否可以添加“else”语句+打印“找不到键/值”,如果没有键,值?更新为我认为你的意思。太棒了!试过了,很完美!格雷西亚斯·汀布莱克先生!谢谢,工作了!我更喜欢你刚才向我展示的“data.iteritems()”方式,我将对此进行更多的研究,再次感谢。想问你,目前“for”语句打印值,是否可以添加“else”语句+打印“找不到键/值”,如果没有键,值?更新为我认为你的意思。太棒了!试过了,很完美!格雷西亚斯·汀布莱克先生!谢谢,工作了!我更喜欢你刚才向我展示的“data.iteritems()”方式,我将对此进行更多的研究,再次感谢。想问你,目前“for”语句打印值,是否可以添加“else”语句+打印“找不到键/值”,如果没有键,值?更新为我认为你的意思。太棒了!试过了,很完美!格雷西亚斯·汀布莱克先生!谢谢,工作了!我更喜欢你刚才向我展示的“data.iteritems()”方式,我将对此进行更多的研究,再次感谢。想问你,目前“for”语句打印值,是否可以添加“else”语句+打印“找不到键/值”,如果没有键,值?更新为我认为你的意思。太棒了!试过了,很完美!格雷西亚斯·汀布莱克先生!