如何在python中解析和获取JSON的结果

时间:2013-05-28 23:45:59

标签: python json

我正在尝试从JSON中提取一个值。

search_results = urllib2.urlopen(request)
for result in search_results:
    print result;

打印结果

{"preview":false,"offset":1,"lastrow":true,"result":{"_bkt":"main~48~BF0767A8-59E9-4783-BB86-F5693835BF2F","_cd":"48:395947656","_indextime":"1369783573","_raw":"2013-05-28 23:05:43 3094 100.244.106.180 200 TCP_NC_MISS 321 967 GET http www.naver.com 80 /include/themecast/menu_count.json - - - - www.naver.com text/html;%20charset=UTF-8 \"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/277.0.1453.93 Safari/537.36\" OBSERVED \"Central_AllWhiteList\" - 104.244.128.30 SG-HTTP-Service 55707 - \"Central_AllWhiteList;Central_AllDoNotAuth;Search Engines/Portals\" http://www.naver.com/ json http://www.naver.com/include/themecast/menu_count.json 63.80.4.67 www.naver.com","_serial":"1","_si":["test.com","main"],"_sourcetype":"Bluecoat","_time":"2013-05-28 16:05:43.000 PDT","host":"dssd-sdfsd-001","index":"main","linecount":"1","source":"D:\\OutSPLNK\\SG__10_244_128_30__052813__230919.log.gz","sourcetype":"sadqw","splunk_server":"test.com"}}

我想从键['_raw']中提取值 这样做的方法是什么?

1 个答案:

答案 0 :(得分:5)

类似的东西:

import json
json_data = json.loads(result)
stuff = json_data['result']['_raw']