0

如何解析 json 输出仅从数据中获取列表,然后将输出添加到 google.com/confidetial 和列表中的其他字符串中。所以我的 json 输出我将其命名为“文本”

text = {"success":true,"code":200,"data":["Confidential","L1","Secret","Secret123","foobar","maret1","maret2","posted","rontest"],"errs":[],"debugs":[]}.

我要做的是仅获取数据下的列表。到目前为止,我得到的脚本给了我整个 json 输出。

json.loads(text)
print text 
output = urllib.urlopen("http://google.com" % text)
print output.geturl()
print output.read()
4

3 回答 3

3
jsonobj = json.loads(text)
print jsonobj['data']

data将在您的 JSON 部分打印列表。

如果你想在 之后打开每个链接google.com,你可以试试这个:

def processlinks(text):
    output = urllib.urlopen('http://google.com/' % text)
    print output.geturl()
    print output.read()

map(processlinks, jsonobj['data'])
于 2013-07-16T13:46:15.033 回答
0

也许像这样result你的 JSON 数据在哪里:

from itertools import product

base_domains = ['http://www.google.com', 'http://www.example.com']
result = {"success":True,"code":200,"data":["Confidential","L1","Secret","Secret123","foobar","maret1","maret2","posted","rontest"],"errs":[],"debugs":[]}
for path in product(base_domains, result['data']):
    print '/'.join(path) # do whatever

http://www.google.com/Confidential
http://www.google.com/L1
http://www.google.com/Secret
http://www.google.com/Secret123
http://www.google.com/foobar
http://www.google.com/maret1
http://www.google.com/maret2
http://www.google.com/posted
http://www.google.com/rontest
http://www.example.com/Confidential
http://www.example.com/L1
http://www.example.com/Secret
http://www.example.com/Secret123
http://www.example.com/foobar
http://www.example.com/maret1
http://www.example.com/maret2
http://www.example.com/posted
http://www.example.com/rontest
于 2013-07-16T13:55:59.147 回答
0
info = json.loads(text)
json_text = json.dumps(info["data"])

Using将从后面json.dumps得到的 python 数据结构转换json.loads为常规的 json 文本。

因此,您可以在之前使用json_text的任何地方使用text它,并且在您的情况下,它应该只有选定的密钥:"data".

于 2013-07-16T13:49:50.957 回答