#!/usr/bin/env python
# -*- coding: utf-8 -*-
#author:nancydai
import types
import json
class apiValue:
# 获取字典中的objkey对应的值,适用于字典嵌套
# dict:字典
# objkey:目标key
# default:找不到时返回的默认值
def dict_get(self, dict, objkey, default):
tmp = dict
for k, v in tmp.items():
if k == objkey:
return v
else:
if type(v) is types.DictType:
ret = self.dict_get(v, objkey, default)
if ret is not default:
return ret
return default
jsonvalue ={u'msg': u'\u6210\u529f', u'currDate': u'2019-01-17 14:01:49', u'code': 200, u'data': {u'analysisModelFields': {u'115088951357734912': [{u'checked': True, u'dataType': u'binary(0)', u'tableName': u'v_balance_of_payments', u'comments': u'\u589e\u957f\u7387', u'aliasName': None, u'fieldType': u'measure', u'fieldName': u'income_grow_rate'}, {u'checked': True, u'dataType': u'int(7)', u'tableName': u'v_balance_of_payments', u'comments': u'\u4e1a\u52a1\u652f\u51fa', u'aliasName': None, u'fieldType': u'measure', u'fieldName': u'bus_outcome'}, {u'checked': True, u'dataType': u'int(4)', u'tableName': u'v_balance_of_payments', u'comments': u'\u5e74-\u534a\u5e74', u'aliasName': None, u'fieldType': u'measure', u'fieldName': u'year_half_year_code'}, {u'checked': True, u'dataType': u'decimal(13,10)', u'tableName': u'v_balance_of_payments', u'comments': u'\u6536\u652f\u7ed3\u4f59\u7387', u'aliasName': None, u'fieldType': u'measure', u'fieldName': u'balance_of_payments'}, {u'checked': True, u'dataType': u'int(7)', u'tableName': u'v_balance_of_payments', u'comments': u'\u533b\u7597\u6536\u5165', u'aliasName': None, u'fieldType': u'measure', u'fieldName': u'medical_income'}, {u'checked': True, u'dataType': u'int(4)', u'tableName': u'v_balance_of_payments', u'comments': u'\u5e74-\u5b63', u'aliasName': None, u'fieldType': u'measure', u'fieldName': u'year_season_code'}, {u'checked': True, u'dataType': u'int(7)', u'tableName': u'v_balance_of_payments', u'comments': u'\u533b\u7597\u6210\u672c', u'aliasName': None, u'fieldType': u'measure', u'fieldName': u'medical_all_cost'}, {u'checked': True, u'dataType': u'int(1)', u'tableName': u'v_balance_of_payments', u'comments': u'\u533b\u9662\u7f16\u7801', u'aliasName': None, u'fieldType': u'measure', u'fieldName': u'hosp_code'}, {u'checked': True, u'dataType': u'int(8)', u'tableName': u'v_balance_of_payments', u'comments': u'\u4e1a\u52a1\u6536\u5165', u'aliasName': None, u'fieldType': u'measure', u'fieldName': u'bus_income'}, {u'checked': True, u'dataType': u'varchar(5)', u'tableName': u'v_balance_of_payments', u'comments': u'\u533b\u9662\u540d\u79f0', u'aliasName': None, u'fieldType': u'measure', u'fieldName': u'hosp_name'}, {u'checked': True, u'dataType': u'int(4)', u'tableName': u'v_balance_of_payments', u'comments': u'\u5e74', u'aliasName': None, u'fieldType': u'dimension', u'fieldName': u'year_code'}, {u'checked': True, u'dataType': u'int(4)', u'tableName': u'v_balance_of_payments', u'comments': u'\u5e74-\u6708', u'aliasName': None, u'fieldType': u'dimension', u'fieldName': u'year_month_code'}, {u'checked': True, u'dataType': u'varchar(8)', u'tableName': u'v_balance_of_payments', u'comments': u'\u7ef4\u5ea6', u'aliasName': None, u'fieldType': u'dimension', u'fieldName': u'dimension'}, {u'checked': True, u'dataType': u'binary(0)', u'tableName': u'v_balance_of_payments', u'comments': u'\u6210\u672c\u63a7\u5236\u7387', u'aliasName': None, u'fieldType': u'measure', u'fieldName': u'cost_control_rate'}]}, u'controlModel': {u'key': u'115138501816614912', u'updateTime': u'2018-12-06 09:01:24.0', u'code': None, u'name': u'\u6536\u652f\u7ed3\u4f59\u7387\u660e\u7ec6', u'creator': u'suishanwen', u'type': u'table', u'remark': u'', u'createTime': u'2018-08-14 17:19:18.0', u'content': u'{"Report":{"ReportHeader":{"Items":{"Tables":[],"TextBoxs":[]},"height":80,"isShow":false},"ReportBody":{"Items":{"Tables":[{"type":"table","fixedHeader":true,"pageTotalRows":20,"fixedColumn":true,"position":{"x":0,"y":0},"columns":[{"fieldName":"hosp_name","type":"dimension","width":"","style":"","isSort":false,"isShow":true,"comments":"\u533b\u9662\u540d\u79f0","sortfieldName":""},{"fieldName":"bus_income","type":"measure","width":"","style":"","isSort":false,"isShow":true,"comments":"\u4e1a\u52a1\u6536\u5165","sortfieldName":""},{"fieldName":"bus_outcome","type":"measure","width":"","style":"","isSort":false,"isShow":true,"comments":"\u4e1a\u52a1\u652f\u51fa","sortfieldName":""},{"fieldName":"balance_of_payments","type":"measure","width":"","style":"","isSort":false,"isShow":true,"comments":"\u6536\u652f\u7ed3\u4f59\u7387","sortfieldName":""},{"fieldName":"medical_income","width":"","type":"measure","style":"","isSort":false,"comments":"\u533b\u7597\u6536\u5165","sortfieldName":""},{"fieldName":"income_grow_rate","width":"","type":"measure","style":"","isSort":false,"comments":"\u589e\u957f\u7387","sortfieldName":""},{"fieldName":"medical_all_cost","width":"","type":"measure","style":"","isSort":false,"comments":"\u533b\u7597\u6210\u672c","sortfieldName":""},{"fieldName":"cost_control_rate","width":"","type":"measure","style":"","isSort":true,"comments":"\u6210\u672c\u63a7\u5236\u7387","sortfieldName":""},{"fieldName":"hosp_code","width":"","type":"measure","style":"","isSort":false,"comments":"\u533b\u9662\u7f16\u7801","sortfieldName":"","isShow":false}],"heights":[28,28],"widths":[219,111,109,105,109,119,101,107,80],"corner":[[]],"body":[[{"rowspan":1,"colspan":1,"display":1,"textBox":{"autoWrap":true,"name":"","location":{"left":0,"top":0},"size":{"width":84,"height":28},"backGroundColor":"rgba(255, 255, 255, 0.1)","fontColor":"none","horizontalAlignment":"Left","verticalAlignment":"Middle","fontInfo":{"family":"Arial","size":12,"fontType":"Normal","fontWeight":"Normal","fontDecoration":"Normal"},"value":"=Fields.hosp_name","formatObject":{},"action":{},"frameBorder":{"borderWidths":{"top":1,"bottom":1,"left":1,"right":1},"borderLineStyles":{"left":"hidden","right":"hidden","top":"hidden","bottom":"hidden"},"borderColors":{"top":"Transparent","bottom":"Transparent","left":"Transparent","right":"Transparent"},"borderShowStyle":{"top":"hidden","bottom":"hidden","left":"hidden","right":"hidden"},"padding":{"top":"2px","bottom":"2px","left":"2px","right":"2px"}},"borderColor":"Transparent","borderWidth":1,"borderStyle":"hidden","borderPadding":"2px","id":"C36BB711_1187_5B38_E470_40C53DCC4BEC","dataType":"string"}},{"rowspan":1,"colspan":1,"display":1,"textBox":{"autoWrap":true,"name":"","location":{"left":0,"top":0},"size":{"width":84,"height":28},"backGroundColor":"rgba(255, 255, 255, 0.1)","fontColor":"none","horizontalAlignment":"Right","verticalAlignment":"Middle","fontInfo":{"family":"Arial","size":12,"fontType":"Normal","fontWeight":"Normal","fontDecoration":"Normal"},"value":"=Fields.bus_income","formatObject":{"type":"Currency","pattern":"#,##0.00;-#,##0.00"},"action":{"conditions":[],"linkAgeSource":"","target":"","targetObject":[]},"frameBorder":{"borderWidths":{"top":1,"bottom":1,"left":1,"right":1},"borderLineStyles":{"left":"hidden","right":"hidden","top":"hidden","bottom":"hidden"},"borderColors":{"top":"Transparent","bottom":"Transparent","left":"Transparent","right":"Transparent"},"borderShowStyle":{"top":"hidden","bottom":"hidden","left":"hidden","right":"hidden"},"padding":{"top":"2px","bottom":"2px","left":"2px","right":"2px"}},"borderColor":"Transparent","borderWidth":1,"borderStyle":"hidden","borderPadding":"2px","id":"CC837EAC_F07B_6534_FE22_3043114D816E","dataType":"int","contentSourceStyle":"Number"}},{"rowspan":1,"colspan":1,"display":1,"textBox":{"autoWrap":true,"name":"","location":{"left":0,"top":0},"size":{"width":84,"height":28},"backGroundColor":"rgba(255, 255, 255, 0.1)","fontColor":"none","horizontalAlignment":"Right","verticalAlignment":"Middle","fontInfo":{"family":"Arial","size":12,"fontType":"Normal","fontWeight":"Normal","fontDecoration":"Normal"},"value":"=Fields.bus_outcome","formatObject":{"type":"Currency","pattern":"#,##0.00;-#,##0.00"},"action":{"conditions":[],"linkAgeSource":"","target":"","targetObject":[]},"frameBorder":{"borderWidths":{"top":1,"bottom":1,"left":1,"right":1},"borderLineStyles":{"left":"hidden","right":"hidden","top":"hidden","bottom":"hidden"},"borderColors":{"top":"Transparent","bottom":"Transparent","left":"Transparent","right":"Transparent"},"borderShowStyle":{"top":"hidden","bottom":"hidden","left":"hidden","right":"hidden"},"padding":{"top":"2px","bottom":"2px","left":"2px","right":"2px"}},"borderColor":"Transparent","borderWidth":1,"borderStyle":"hidden","borderPadding":"2px","id":"C20E4AB4_D408_EB4C_FA2D_AB5D5CB66186","dataType":"int","contentSourceStyle":"Number"}},{"rowspan":1,"colspan":1,"display":1,"textBox":{"autoWrap":true,"name":"","location":{"left":0,"top":0},"size":{"width":84,"height":28},"backGroundColor":"rgba(255, 255, 255, 0.1)","fontColor":"none","horizontalAlignment":"Right","verticalAlignment":"Middle","fontInfo":{"family":"Arial","size":12,"fontType":"Normal","fontWeight":"Normal","fontDecoration":"Normal"},"value":"=Fields.balance_of_payments","formatObject":{"type":"Number","pattern":"#,##0.00%;-#,##0.00%"},"action":{"conditions":[],"linkAgeSource":"","target":"","targetObject":[]},"frameBorder":{"borderWidths":{"top":1,"bottom":1,"left":1,"right":1},"borderLineStyles":{"left":"hidden","right":"hidden","top":"hidden","bottom":"hidden"},"borderColors":{"top":"Transparent","bottom":"Transparent","left":"Transparent","right":"Transparent"},"borderShowStyle":{"top":"hidden","bottom":"hidden","left":"hidden","right":"hidden"},"padding":{"top":"2px","bottom":"2px","left":"2px","right":"2px"}},"borderColor":"Transparent","borderWidth":1,"borderStyle":"hidden","borderPadding":"2px","id":"CD86DE5C_5C70_33DC_382F_93DF5E9E408B","dataType":"string","contentSourceStyle":"Number"}},{"rowspan":1,"colspan":1,"display":1,"textBox":{"id":"C0367201_259B_BECE_EAE8_717DA2604BF3","horizontalAlignment":"Right","value":"=Fields.medical_income","dataType":"int","contentSourceStyle":"Number","formatObject":{"type":"Currency","pattern":"#,##0.00;-#,##0.00"}}},{"rowspan":1,"colspan":1,"display":1,"textBox":{"id":"C18FB237_83E7_D3A8_CC15_8485F8EE54DA","horizontalAlignment":"Right","value":"=Fields.income_grow_rate","dataType":"string","contentSourceStyle":"Number","formatObject":{"type":"Percent","pattern":"0.00%;-0.00%"}}},{"rowspan":1,"colspan":1,"display":1,"textBox":{"id":"C8600538_B487_B867_E664_1A4C87B267B7","horizontalAlignment":"Right","value":"=Fields.medical_all_cost","dataType":"int","contentSourceStyle":"Number","formatObject":{"type":"Currency","pattern":"#,##0.00;-#,##0.00"}}},{"rowspan":1,"colspan":1,"display":1,"textBox":{"id":"C92B4A50_1B9D_02F3_FB5F_187F5356F889","horizontalAlignment":"Right","value":"=Fields.cost_control_rate","dataType":"string","contentSourceStyle":"Number","formatObject":{"type":"Percent","pattern":"0.00%;-0.00%"}}},{"rowspan":1,"colspan":1,"display":1,"textBox":{"id":"C74033F1_6CBC_6D99_0E60_54A45434F6C6","horizontalAlignment":"Right","value":"=Fields.hosp_code","dataType":"int"}}]],"columnHierarchy":[{"content":{"textBox":{"autoWrap":true,"name":"","location":{"left":0,"top":0},"size":{"width":84,"height":28},"backGroundColor":"rgba(245,245,245,1)","fontColor":"none","horizontalAlignment":"Center","verticalAlignment":"Middle","fontInfo":{"family":"Arial","size":12,"fontType":"Normal","fontWeight":"Normal","fontDecoration":"Normal"},"value":"\u533b\u9662\u540d\u79f0","formatObject":{},"action":{"conditions":[],"linkAgeSource":"","target":"","targetObject":[]},"frameBorder":{"borderWidths":{"top":1,"bottom":1,"left":1,"right":1},"borderLineStyles":{"left":"hidden","right":"hidden","top":"hidden","bottom":"hidden"},"borderColors":{"top":"Transparent","bottom":"Transparent","left":"Transparent","right":"Transparent"},"borderShowStyle":{"top":"hidden","bottom":"hidden","left":"hidden","right":"hidden"},"padding":{"top":"2px","bottom":"2px","left":"2px","right":"2px"}},"borderColor":"Transparent","borderWidth":1,"borderStyle":"hidden","borderPadding":"2px","id":"CABE03CD_B724_FA6C_6202_54DBCBA8BB1C","dataType":"string"}},"rowspan":1,"colspan":1,"height":28,"children":[],"start":0,"pos":0},{"content":{"textBox":{"autoWrap":true,"name":"","location":{"left":0,"top":0},"size":{"width":84,"height":28},"backGroundColor":"rgba(245,245,246,1)","fontColor":"none","horizontalAlignment":"Center","verticalAlignment":"Middle","fontInfo":{"family":"Arial","size":12,"fontType":"Normal","fontWeight":"Normal","fontDecoration":"Normal"},"value":"\u4e1a\u52a1\u6536\u5165(\u4e07\u5143)","formatObject":{},"action":{"conditions":[],"linkAgeSource":"","target":"","targetObject":[]},"frameBorder":{"borderWidths":{"top":1,"bottom":1,"left":1,"right":1},"borderLineStyles":{"left":"hidden","right":"hidden","top":"hidden","bottom":"hidden"},"borderColors":{"top":"Transparent","bottom":"Transparent","left":"Transparent","right":"Transparent"},"borderShowStyle":{"top":"hidden","bottom":"hidden","left":"hidden","right":"hidden"},"padding":{"top":"2px","bottom":"2px","left":"2px","right":"2px"}},"borderColor":"Transparent","borderWidth":1,"borderStyle":"hidden","borderPadding":"2px","id":"CE2FDEB7_040B_158B_F9E4_CC161EC9CCF3","dataType":"string"}},"rowspan":1,"colspan":1,"height":28,"children":[],"start":1,"pos":0},{"content":{"textBox":{"autoWrap":true,"name":"","location":{"left":0,"top":0},"size":{"width":84,"height":28},"backGroundColor":"rgba(245,245,245,1)","fontColor":"none","horizontalAlignment":"Center","verticalAlignment":"Middle","fontInfo":{"family":"Arial","size":12,"fontType":"Normal","fontWeight":"Normal","fontDecoration":"Normal"},"value":"\u4e1a\u52a1\u652f\u51fa(\u4e07\u5143)","formatObject":{},"action":{"conditions":[],"linkAgeSource":"","target":"","targetObject":[]},"frameBorder":{"borderWidths":{"top":1,"bottom":1,"left":1,"right":1},"borderLineStyles":{"left":"hidden","right":"hidden","top":"hidden","bottom":"hidden"},"borderColors":{"top":"Transparent","bottom":"Transparent","left":"Transparent","right":"Transparent"},"borderShowStyle":{"top":"hidden","bottom":"hidden","left":"hidden","right":"hidden"},"padding":{"top":"2px","bottom":"2px","left":"2px","right":"2px"}},"borderColor":"Transparent","borderWidth":1,"borderStyle":"hidden","borderPadding":"2px","id":"C1BAA4CD_C584_6080_2BBC_F8A159E92A08","dataType":"string"}},"rowspan":1,"colspan":1,"height":28,"children":[],"start":2,"pos":0},{"content":{"textBox":{"autoWrap":true,"name":"","location":{"left":0,"top":0},"size":{"width":84,"height":28},"backGroundColor":"rgba(245,245,245,1)","fontColor":"none","horizontalAlignment":"Center","verticalAlignment":"Middle","fontInfo":{"family":"Arial","size":12,"fontType":"Normal","fontWeight":"Normal","fontDecoration":"Normal"},"value":"\u6536\u652f\u7ed3\u4f59\u7387(%)","formatObject":{},"action":{"conditions":[],"linkAgeSource":"","target":"","targetObject":[]},"frameBorder":{"borderWidths":{"top":1,"bottom":1,"left":1,"right":1},"borderLineStyles":{"left":"hidden","right":"hidden","top":"hidden","bottom":"hidden"},"borderColors":{"top":"Transparent","bottom":"Transparent","left":"Transparent","right":"Transparent"},"borderShowStyle":{"top":"hidden","bottom":"hidden","left":"hidden","right":"hidden"},"padding":{"top":"2px","bottom":"2px","left":"2px","right":"2px"}},"borderColor":"Transparent","borderWidth":1,"borderStyle":"hidden","borderPadding":"2px","id":"C062955E_98C9_D083_DCC5_1BC8E678680E","dataType":"string"}},"rowspan":1,"colspan":1,"height":28,"children":[],"start":3,"pos":0},{"content":{"textBox":{"id":"C89A4F9D_348B_3A5B_9CB5_3C84C6DF4B42","value":"\u533b\u7597\u6536\u5165(\u4e07\u5143)","dataType":"string","horizontalAlignment":"Center","autoWrap":true,"name":"","location":{"left":0,"top":0},"size":{"width":84,"height":28},"backGroundColor":"rgba(245,245,245,1)","fontColor":"none","verticalAlignment":"Middle","fontInfo":{"family":"Arial","size":12,"fontType":"Normal","fontWeight":"Normal","fontDecoration":"Normal"},"formatObject":{},"frameBorder":{"borderWidths":{"top":1,"bottom":1,"left":1,"right":1},"borderLineStyles":{"left":"hidden","right":"hidden","top":"hidden","bottom":"hidden"},"borderColors":{"top":"Transparent","bottom":"Transparent","left":"Transparent","right":"Transparent"},"borderShowStyle":{"top":"hidden","bottom":"hidden","left":"hidden","right":"hidden"},"padding":{"top":"2px","bottom":"2px","left":"2px","right":"2px"}},"borderColor":"Transparent","borderWidth":1,"borderStyle":"hidden","borderPadding":"2px"}},"rowspan":1,"colspan":1,"height":28,"children":[],"start":4,"pos":0},{"content":{"textBox":{"id":"CE81BCB0_2690_8F39_E0F0_5B3FBE8A8302","value":"\u533b\u7597\u6536\u5165\u589e\u957f\u7387(%)","dataType":"string","horizontalAlignment":"Center","backGroundColor":"rgba(245,245,245,1)"}},"rowspan":1,"colspan":1,"height":28,"children":[],"start":5,"pos":0},{"content":{"textBox":{"id":"CA6ED769_559A_C444_ADF7_9FFA40299703","value":"\u533b\u7597\u6210\u672c(\u4e07\u5143)","dataType":"string","horizontalAlignment":"Center","backGroundColor":"rgba(245,245,245,1)"}},"rowspan":1,"colspan":1,"height":28,"children":[],"start":6,"pos":0},{"content":{"textBox":{"id":"CA6AEB80_463B_9BC6_0B92_0DDB59732548","value":"\u6210\u672c\u63a7\u5236\u7387(%)","dataType":"string","horizontalAlignment":"Center","backGroundColor":"rgba(245,245,245,1)"}},"rowspan":1,"colspan":1,"height":28,"children":[],"start":7,"pos":0},{"content":{"textBox":{"id":"CAAEAACD_7EB2_B6B1_D382_186ADFC2BD93","value":"\u533b\u9662\u7f16\u7801","dataType":"string","horizontalAlignment":"Center"}},"rowspan":1,"colspan":1,"height":28,"children":[],"start":8,"pos":0}],"rowHierarchy":[{"name":"\u8be6\u7ec6\u4fe1\u606f","pos":0,"group":[],"sort":[],"start":1,"end":1,"children":[]}],"tableProperty":{"isPaging":true,"fixedColumn":true,"groupLevelField":"","isBorder":"yes","HeadData":{"height":80,"isShow":false,"textBoxes":[]}}}],"TextBoxs":[]}},"ReportFooter":{"Items":{"Tables":[],"TextBoxs":[]},"height":80,"isShow":false},"dataSets":[{"analysisModelId":"115088951357734912","conditions":[],"modelSpecialAttr":null,"fields":["hosp_name","bus_income","bus_outcome","balance_of_payments","medical_income","income_grow_rate","medical_all_cost","cost_control_rate","hosp_code"],"pageSize":100,"showDetailRow":true,"groupFields":[],"totalFields":[],"isPaging":true,"fixedColumn":true,"groupLevelField":"","collapse":true,"tableSort":"","liftingSequence":"ascend","yearTotalParameter":"","totalFieldsExpressions":{}}]}}', u'analysis_module_id': u'115088951357734912', u'score': 1544058084000.0, u'updater': u'7dafc690-0b8a-4014-ab61-1167b7d880f5', u'is_remove': u'0', u'backgroundPictureKey': None, u'conditions': None, u'id': u'115138501816614912', u'category_id': u'105341784493654016'}, u'controlData': {u'footerData': None, u'total': 1, u'list': [{u'bus_income': 39900.852944, u'cost_control_rate': -0.111111, u'medical_income': 32841.877936, u'half_year_code': None, u'year_month_code': u'2018-12', u'year_season_code': u'2018-12', u'bus_outcome': 46131.565536, u'season_code': None, u'month_code': 12, u'balance_of_payments': -0.250657, u'year_half_year_code': u'2018-12', u'hosp_name': u'\u5317\u4eac\u5e02\u6d77\u6dc0\u533a\u5987\u5e7c\u4fdd\u5065\u9662', u'medical_all_cost': 46633.296384, u'year_code': 2018, u'dimension': u'2018-12', u'income_grow_rate': -0.095442, u'hosp_code': u'100102'}]}}}
value1=apiValue().dict_get(jsonvalue,'controlData',0)
value2=apiValue().dict_get(value1,'list',0)[0]['bus_income']
print value2
运行结果:
39900.852944
|