世界坦克Python列表比较来自json

时间:2015-09-19 05:31:04

标签: json list python-2.7 parsing

好的我正在尝试创建一个定义,它将从外部Json文件读取IDS列表,它正在做什么。它甚至在加载程序时将数据放入数据库,我的问题是这个。我似乎无法将列表ID与比较匹配。这是我目前的代码:

def check(account):
global ID_account
import json, httplib
if not hasattr(BigWorld, 'iddata'):
    UID_DB = account['databaseID']
    UID = ID_account
    try:
        conn = httplib.HTTPConnection('URL')
        conn.request('GET', '/ids.json')
        conn.sock.settimeout(2)
        resp = conn.getresponse()
        qresp = resp.read()
        BigWorld.iddata = json.loads(qresp)
        LOG_NOTE('[ABRO] Request of URL data successful.')
        conn.close()
    except:
        LOG_NOTE('[ABRO] Http request to URL problem. Loading local data.')
    if UID_DB is not None:
        list = BigWorld.iddata["ids"]
        #print (len(list) - 1)
        for n in range(0, (len(list) - 1)):
            #print UID_DB
            #print list[n]
            if UID_DB == list[n]:
                #print '[ABRO] userid located:'
                #print UID_DB
                UID = UID_DB
    else:
        LOG_NOTE('[ABRO] userid not set.')  
    if 'databaseID' in account and account['databaseID'] != UID:
        print '[ABRO] Account not active in database, game closing...... '
        BigWorld.quit()

现在我的json文件看起来像这样:

{
"ids":[
  "1001583757",
  "500687699",
  "000000000"
  ]
}

现在,当我使用所有已注释的打印件运行它时,它似乎执行完全正常,直到它尝试在for循环内进行匹配。即使打印显示UID_DB和list [n]是相同的值,它也不会设置我的变量,它不会发布任何错误,它只是表现得好像没有匹配。我可能错过了一个循环中断?这是python日志,以打印表格的长度开始:

INFO: 2
INFO: 1001583757
INFO: 1001583757
INFO: 1001583757
INFO: 500687699
INFO: [ABRO] Account not active, game closing...... 

从日志中可以看出,它从不打印用户所在的打印,因此它们不匹配。它只是继续循环并使用我在定义上面定义的默认ID。任何有想法的人肯定会帮助我,因为我已经开始刺激和刺激这件事3天了。

0 个答案:

没有答案