我是python的新手。我需要从json文件中提取数据。
import urllib
import re
import json
text = urllib.urlopen("http://www.acer.com/wjws/ws/gdp/files/en/IN/-/latest/driver/63/-").read()
result = json.loads(text) # result is now a dict
print result['Files']['OS']['Id']
我需要从JSON链接
上面的“文件”中的“OS”中提取“Id”字段我收到的错误是: TypeError:list indices必须是整数,而不是str
链接包含数据
{ “档案”:{ “结果”:“好”, “语言”: [ { “Id”:“bg”, “标题”:“保加利亚语” },
{ "Id": "no", "Title": "Norwegian" }, ], "SearchedLanguage": "en", "OS": [ { "Id": "001", "Title": "Windows® 2000 Professional" }, { "Id": "098", "Title": "Windows® 98" }, { "Id": "0ME", "Title": "Windows® ME" }, { "Id": "X02", "Title": "Windows® XP 32-bit" }, { "Id": "X05", "Title": "Windows® XP 64-bit" } ], "File": [ { "Link": "http:\/\/global-download.acer.com\/GDFiles\/Driver\/VGA\/VGA_VIA_1.0_w2k.zip?acerid=633676006896131590", "Category": "VGA", }, ] } }
答案 0 :(得分:0)
将最后一行代码更改为
打印结果['文件'] ['操作系统'] [0] [' Id']
它将获得OS中的第一个ID。
答案 1 :(得分:0)
尝试如下....
for i in range(len(result['Files']['OS'])):
print result['Files']['OS'][i]['Id'];
output
======
001
001
098
0ME
X02
X05