主要反应数据表组件从数组到 JSON 的数据转换?

问题描述

每当我使用输入参数 fileLookup 调用 java 网络服务 (HTTP GET) lookupId 时,它都会以如下所示的数组形式返回响应。

[
    "1224,First_File.docx,null,458,null","1225,Second File.js,test for description,15514,778,"1226,Third_File.pdf,876,null"
]

收到的响应值对应于以下字段。

File id    File Name    Description   user Id  File Version

例如,在1224,null的情况下,1224File idFirst_File.docxFile Namenull是{{1} },Description 分别为 458user Id 分别为 null

我想显示一个primereact数据表,它将显示在表中的东西之上。但是,我发现的大多数示例都使用 JSON 数据。例如,this sandbox example。就我而言,由于我没有 JSON 对象形式的数据,我是否应该首先考虑将上述数据转换为 JSON,以便我可以将其提供给数据表或其他任何可以实现相同目的的数据?

解决方法

你需要的是什么

this

您创建一个新数组,用“,”分割每个字符串,然后将索引用作 from PyQt5.QtWidgets import * from PyQt5.QtCore import * from PyQt5.QtGui import * from PyQt5.uic import loadUiType import os from os import path import sys import urllib from urllib.request import urlopen import urllib.request import pafy import humanize FORM_CLASS,_ = loadUiType(path.join(path.dirname(__file__),"MainDownloader.ui")) class MainApp(QMainWindow,FORM_CLASS): def __init__(self,parent=None): super(MainApp,self).__init__(parent) QMainWindow.__init__(self) self.setupUi(self) self.Handel_UI() self.Handel_Botton() def Handel_UI(self): self.setWindowTitle('PY Downloader') self.setFixedSize(800,368) def Handel_Botton(self): self.pushButton.clicked.connect(self.Download) self.pushButton_2.clicked.connect(self.Handel_Browse) self.pushButton_11.clicked.connect(self.Get_Youtube_video) self.pushButton_8.clicked.connect(self.Download_Youtube_video) self.pushButton_7.clicked.connect(self.Save_Browse) self.pushButton_10.clicked.connect(self.Save_Browse) self.pushButton_9.clicked.connect(self.playlist_Download) def Handel_Browse(self): save_palce = QFileDialog.getSaveFileName(self,caption="Save As",directory="C:/Users/Saleh saleh/Downloads",filter="All Files (*.*)") text = str(save_palce) name = (text[2:-1].split(',')[0].replace("'",'')) self.lineEdit_2.setText(name) def Handel_Progress(self,blocknum,blocksize,totalsize): read = blocknum * blocksize if totalsize > 0: percent = read * 100 / totalsize self.progressBar.setValue(percent) QApplication.processEvents() def Download(self): url = self.lineEdit.text() save_location = self.lineEdit_2.text() try: urllib.request.urlretrieve(url,save_location,self.Handel_Progress) except Exception: QMessageBox.warning(self,"Download Error","The Download Faild") return QMessageBox.information(self,"Download Completed","The Download Finished") self.progressBar.setValue(0) self.lineEdit.setText('') self.lineEdit_2.setText('') def Save_Browse(self): save = QFileDialog.getExistingDirectory(self,"Select Download Direcyory") self.lineEdit_8.setText(save) self.lineEdit_9.setText(save) def Get_Youtube_video(self): video_link = self.lineEdit_3.text() v = pafy.new(video_link) st = v.videostreams for s in st: size = humanize.naturalsize(s.get_filesize()) data = '{} {} {} {}'.format(s.mediatype,s.extension,s.quality,size) self.comboBox.addItem(data) def Download_Youtube_video(self): video_link = self.lineEdit_3.text() save_location = self.lineEdit_8.text() v = pafy.new(video_link) st = v.videostreams quality = self.comboBox.currentIndex() print(quality) Down = st[quality].download(filepath=save_location) QMessageBox.information(self,"The Video Download Finished") def playlist_Download(self): playlist_url = self.lineEdit_10.text() save_location = self.lineEdit_9.text() #playlist = pafy.get_playlist(playlist_url) playlist2 = pafy.get_playlist2(playlist_url) videos = playlist,playlist2['items'] os.chdir(save_location) if os.path.exists(str(playlist,playlist2['title'])): os.chdir(str(playlist,playlist2['title'])) else: os.mkdir(str(playlist,playlist2['title'])) os.chdir(str(playlist,playlist2['title'])) for video in videos: p = video['pafy'] best = p.getbest(preftype='mp4') best.dowload(p) def main(): app = QApplication(sys.argv) window = MainApp() window.show() app.exec_() if __name__ == '__main__': main() 组件中的字段。

DataTable