开发者

Python Json Parsing

I'm having a bit of an issue with parsing json with python using the json library. Here is the format of the json I'm trying to parse:

{'entry':[
    {

        JSON Data 1
    }, 

        JSON Data 2
    }
]}

And here is my Python:

for entry in response['entry'][0]:

    video['video_url'] = entry['id']['$t']
    video['publis开发者_StackOverflow中文版hed'] = entry['published']['$t']

I don't seem to be able to iterate over the two blocks of JSON with the above code, I only get the first block outputted for some reason.

Anybody have any ideas?? Thanks in advance.


If:

response = {'entry':[
    {

        JSON Data 1
    }, 
    {

        JSON Data 2
    }
]}

And:

response['entry'][0] == { JSON Data 1  }

Then:

for entry in response['entry']:

    video['video_url'] = entry['id']['$t']
    video['published'] = entry['published']['$t']

Or:

video = dict(zip(['video_url', 'published'], [entry['id']['$t'], entry['published']['$t']]) for entry in response['entry']


That list contains 2 separate dicts. Iterate over the list directly.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜