【无标题】解析json

import pandas as pd

import datetime

from odps.df import DataFrame

from odps import ODPS

import json

import csv

# 包含起始

id1 = 'ak'

key = 'aks'

point = 'www'

project = 'ods'

odps = ODPS(id1, key, project, endpoint=point)

data1 = DataFrame(odps.get_table('tb_ali_table_info_a_d'))

data1 = data1.to_pandas()

print('11111')

list1 = data1['project']

list2 = data1['middle_table_name']

list3 = data1['table_comment']

list4 = data1['is_partitioned']

list5 = data1['column_name']

list6 = data1['life_cycle']

list_data = []

for i in range(len(list1)):

data = json.loads(list5[i])

list11 = data['cols']

for j in range(len(list11)):

name = list11[j]['name']

try:

type1 = list11[j]['type']

except:

type1 = ''

try:

comment = list11[j]['comment']

except:

comment = ''

list_data.append([list1[i],list2[i],list3[i],list4[i],name,type1,comment,list6[i]])

print('wan')


 

# with open('test.csv', 'w', newline='', encoding='utf-8') as f1:#/root/python_meng/chengxu/

# w1 = csv.writer(f1)

# print(len(list_data))

# for i in range(len(list_data)):

# w1.writerow(list_data[i])


 

today = datetime.datetime.today()

oneday = datetime.timedelta(1)

yesterday = today - oneday

yesterday, time12 = str(yesterday).split(' ')

yesterday = yesterday.replace('-', '')

print('data_date={}'.format(yesterday))

id1 = 'ak'

key = 'aks'

point = 'www'

project = 'dwd'

odps1 = ODPS(id1, key, project, endpoint=point)

t = odps1.get_table('t_ali_table_info_a_d') # 获取读写表权限

patition = 'data_date={}'.format(yesterday)

# 先清空这个分区的数据

t.delete_partition('data_date={}'.format(yesterday), if_exists=True)

print('开始写入数据')

with t.open_writer(patition, create_partition=True) as writer:

print('kaishi')

for i in range(len(list_data)):

try:

writer.write(list_data[i])

except:

pass

# list_row = result[i]

# for j in range(len(list_row)):

# if list_row[j] == 'null':

# list_row[j] = '-1'

# writer.write(list_row)

#writer.write(result)

b_t = datetime.datetime.now()

print('wan')



 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要将JSON数据解析并应用到ListView中,您可以按照以下步骤进行: 1. 获取JSON数据 您可以使用HttpURLConnection或OkHttp等网络库来获取JSON数据。确保在获取数据时处理好异常情况,例如网络不可用或无法连接到服务器。 2. 解析JSON数据 Android提供了一个org.json包,其中包含用于解析JSON数据的类。您可以使用JSONObject和JSONArray类来解析JSON对象和数组。 例如,假设您从服务器上获取了以下JSON数据: ``` { "books": [ { "title": "The Great Gatsby", "author": "F. Scott Fitzgerald" }, { "title": "To Kill a Mockingbird", "author": "Harper Lee" } ] } ``` 您可以使用以下代码解析数据: ```java try { JSONObject jsonObject = new JSONObject(jsonData); JSONArray jsonArray = jsonObject.getJSONArray("books"); ArrayList<Book> bookList = new ArrayList<>(); for (int i = 0; i < jsonArray.length(); i++) { JSONObject bookObj = jsonArray.getJSONObject(i); String title = bookObj.getString("title"); String author = bookObj.getString("author"); bookList.add(new Book(title, author)); } // 将解析的数据应用到ListView中 BookListAdapter adapter = new BookListAdapter(this, bookList); ListView listView = findViewById(R.id.list_view); listView.setAdapter(adapter); } catch (JSONException e) { e.printStackTrace(); } ``` 3. 应用数据到ListView中 创建一个ListView并使用适配器将数据应用到ListView中。您可以创建自己的适配器或使用Android提供的默认适配器,例如ArrayAdapter或SimpleAdapter。 例如,假设您要将解析的书籍数据应用到ListView中,您可以创建一个自定义适配器: ```java public class BookListAdapter extends ArrayAdapter<Book> { private LayoutInflater inflater; public BookListAdapter(Context context, ArrayList<Book> books) { super(context, 0, books); inflater = LayoutInflater.from(context); } @Override public View getView(int position, View convertView, ViewGroup parent) { ViewHolder holder; if (convertView == null) { convertView = inflater.inflate(R.layout.list_item_book, parent, false); holder = new ViewHolder(); holder.titleTextView = convertView.findViewById(R.id.title_text_view); holder.authorTextView = convertView.findViewById(R.id.author_text_view); convertView.setTag(holder); } else { holder = (ViewHolder) convertView.getTag(); } Book book = getItem(position); holder.titleTextView.setText(book.getTitle()); holder.authorTextView.setText(book.getAuthor()); return convertView; } private static class ViewHolder { TextView titleTextView; TextView authorTextView; } } ``` 其中Book是一个自定义类,用于存储书籍的标题和作者信息。 现在,您可以将适配器应用到ListView中: ```java BookListAdapter adapter = new BookListAdapter(this, bookList); ListView listView = findViewById(R.id.list_view); listView.setAdapter(adapter); ``` 请注意,您需要在布局文件中定义ListView和list_item_book布局。 list_item_book布局应该包含用于显示书名和作者的TextView元素。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值