不断收到类型错误 python

Keep getting type error python

我正在使用 jqGrid 进行搜索查询。我的参数如下:

function:GL
_search:true
nd:1446209493437
rows:50
page:1
sidx:datetime
sord:asc
filters:{"groupOp":"AND","rules":[{"field":"username","op":"eq","data":"user"},{"field":"description","op":"nc","data":"utility"}]}
searchField:
searchString:
searchOper:

当我 运行 脚本在本地使用这些值时它工作正常但是当我使用网页和 cgi 时:

C:\wamp\www\ISaidItBest\assets\cgi-bin\app\Log.py in getAllLogs(self=<app.Log.Log object>)
     91                 elif filters:   # filter options
     92                     buildwhere = ""
=>   93                     rules = filters['rules']
     94                     for idx in range(len(rules)):
     95                         field = rules[idx]['field']
rules undefined, filters = '{"groupOp":"AND","rules":[{"field":"username","o...ield":"description","op":"nc","data":"utility"}]}'
TypeError: string indices must be integers 
      args = ('string indices must be integers',) 
      with_traceback = <built-in method with_traceback of TypeError object>

您需要将 filtersstr 转换为 dict。读这个:https://docs.python.org/2/library/json.html#json.loads

尝试:

....
buildwhere = ""
if isinstance(filters, str):
    filters = json.loads(filters)
....