字符串索引在Json中必须是整数

2024-07-01 08:15:13 发布

您现在位置:Python中文网/ 问答频道 /正文

我在由我创建的JSON中得到一个错误,消息是:字符串索引必须是整数。我确实读了一些关于stackoverflow的话题,但是我不清楚我要改变什么

问题在于items = json_data['items']

我的代码:

    formattedUrl = ["https://stackoverflow.com/", "https://en.wikipedia.org/wiki/Main_Page"]
    displayLink = ["https://stackoverflow.com/", "https://en.wikipedia.org/wiki/Main_Page"]
    htmlFormattedUrl = ["https://stackoverflow.com/", "https://en.wikipedia.org/wiki/Main_Page"]
    title = ["Stackoverflow", "Wikipedia, the free encyclopedia"]
    htmlTitle = ["Stackoverflow", "Wikipedia, the free encyclopedia"]
    snippet = ["Stack Overflow is the largest", "Main page"]

    #
    keys = ['formattedUrl', 'displayLink', 'htmlFormattedUrl', 'title', 'htmlTitle', 'snippet']
    items = [dict(zip(keys, [u, t, d, aa, ab, ac])) for u, t, d, aa, ab, ac in
             zip(formattedUrl, displayLink, htmlFormattedUrl, title, htmlTitle, snippet)]

    d = {

        'items': items
    }

    json_data = json.dumps(d, indent=4)


    #queries


    if has_result == 1 :
        # print "results"
        result = []
        results = []

        items = json_data['items']

Tags: httpsorgcomjsondatamainwikipage

热门问题