def json_to_excel(json_array, tag, timeStamp_name_list=[], chinese_dict=None):
    '''
    usage:json数组导成表格
    __author__:xp
    :param json_array: json数组
    :param tag: 主题字段,用于合并单元格
    :param timeStamp_name_list: 时间戳字段名列表,用于格式化时间戳,如果时间数据提前转换为字符串的形式,保持默认[]即可
    :param chinese_dict: 格式化表头所用的字典,json字段名到中文名的映射字典,默认为None
    :return: None 会在同目录下生成一个result.xlsx的表格
    调用示例:
    json_to_excel(json_array=[{'id': 1, 'time': '2009-04-20 04:00:00', 'caller_device': '13'},
                          {'id': 2, 'time': '2009-04-20 04:10:00', 'caller_device': '13'}],
              tag='caller_device',
              timeStamp_name_list=[])
    '''

    data = json_normalize(json_array)
    tag_values = data[tag].value_counts()
    new_data = [data[data[tag] == tag_value] for tag_value in tag_values.index]
    new_data = pd.concat(new_data, ignore_index=True)
    # print(new_data.columns.values)
    new_data = new_data.drop(columns=['id'])
    cols = list(new_data)
    cols.insert(0, cols.pop(cols.index(tag)))
    new_data = new_data.ix[:, cols]
    # print(new_data)
    xlsfile = xlsxwriter.Workbook('result.xlsx')
    merge_format = xlsfile.add_format({
        'bold': True,
        'border': 6,
        'align': 'center',
        'valign': 'vcenter',

    })

    font_format = xlsfile.add_format({
        'align': 'center',
        'valign': 'vcenter',
    })
    d = xlsfile.add_format({'num_format': 'yyyy-MM-dd hh:mm:ss'})
    worksheet = xlsfile.add_worksheet('sheet_1')

    for i, colname in enumerate(list(new_data.columns.values)):
        worksheet.write(0, i,
                        (colname if chinese_dict is None else chinese_dict[colname]),
                        font_format)
        if colname == tag:
            last = 1
            for s in tag_values.index:
                worksheet.merge_range(first_row=last, first_col=i,
                                      last_row=last + tag_values[s] - 1, last_col=i,
                                      data=s, cell_format=merge_format)
                last = last + tag_values[s]
        else:
            if colname in timeStamp_name_list:
                worksheet.write_column(row=1, col=i,
                                       data=[x.strftime('%Y-%m-%d %H:%M:%S')
                                             for x in new_data[colname]])
            else:
                worksheet.write_column(row=1, col=i,
                                       data=list(new_data[colname]),
                                       cell_format=font_format)
    xlsfile.close()