![](/img/trans.png)
[英]How to read large data from temp file in Spotfire using IronPython
[英]How to convert a DataTable into JSON in spotfire using IronPython?
我在Spotfire中有一個數據表,我需要將其轉換為JSON對象。 我在下面的代碼段中工作,但是我需要運行速度更快的代碼。
import clr
import sys
clr.AddReference('System.Web.Extensions')
from System.Web.Script.Serialization import JavaScriptSerializer
from Spotfire.Dxp.Data import IndexSet
from Spotfire.Dxp.Data import DataValueCursor
rowCount = MyTable.RowCount
rows = IndexSet(rowCount,True)
cols = MyTable.Columns
MyTableData=[]
for r in rows:
list={}
item={}
for c in cols:
item[c.Name] = c.RowValues.GetFormattedValue(r)
list['MyData']=item
MyTableData.append(list)
json=JavaScriptSerializer(MaxJsonLength=sys.maxint).Serialize(MyTableData)
我不確定代碼的最后一行有多少開銷,但是如果您將myTableData結果用作字符串來驅動javscript小部件,則不需要它。 嘗試將最后一行替換為
json=str(MyTableData)
看看有多快。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.