簡體   English   中英

如何在python中解析並從JSON獲取結果

[英]how to parse and get result from JSON in 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']中提取值,該怎么做?

就像是:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM