2013-05-28 47 views
0

我想从JSON中提取一个值。如何解析并从python中获取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”] 什么是做到这一点的呢?

+0

JSON *是*文字和'urlopen'返回一个字符串。在可以轻松访问组件之前,必须将JSON解析为对象模型(使用库)。了解这个过程,可以通过“解析JSON”找到许多有用的结果。 – user2246674

回答

5

喜欢的东西:

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