几种json格式取数据小记

本文介绍了两种不同的JSON格式数据的提取方法,包括从复杂结构中获取特定值,如"bus_income=39900.852944"等关键信息。通过实例解析,帮助读者掌握JSON数据处理技巧。
摘要由CSDN通过智能技术生成

格式1:

截图:

 

方法如下:目标:取json数据内的:“bus_income=39900.852944”

#!/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","
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值