首页 > 解决方案 > 使用 ironPython 在 Spotfire DataTable 中显示 JSON 数组结果

问题描述

我有一个 JSON 字符串数组(来自 REST API 调用的结果),如下所示。该字符串数组应在 Spotfire 中使用 IronPython 脚本组织为数据表中的列名和相应记录。所有属性都应显示为我的列名(仅一次),值应显示为记录(迭代)。任何帮助深表感谢。如果您需要更多清晰度,请告诉我。

JSON数据:

[{"actionType":"调整油管或套管 PSI","assignedTeam":"FS","exceptionStatus":"","eventEndDate":"1970-01-01T00:00:00.000Z","description": "电机温度","lastEditedDate":"2019-07-19T02:49:00.945Z","well":{"apiNumber12":"423294206100","area":"MIDLAND BASIN","wellName":"C SCHARB 31WB","asset":"ODESSA EAST FMT","route":"4000003 - NOD","apiNumber14":"42329420610001"},"actionItemPastDueDate":"2019-07-27T02:48:59.000Z", "lastEditedBy":"Agent(System-Queue-ServiceLevel.ProcessEvent)","priorityRangeMax":500.000000000,"currentStage":"ALT5","id":"E-4056","workOrder":"","assignedDate":"2019-07-15T05:00:00.000Z","impactedLpo":true,"alcrApprovalComments":"", "createdDate":"2019-07-16T02:48:34.786Z","alcrApprovalDeadline":"2019-07-19T02:48:59.000Z","dueDate":"2019-07-22T02:48:59.000Z" ,"chemicalAdvisorComments":"","re​​commendationsStripped":"Training Test","workStatus":"Pending-ALCRApproval","actionTakenStripped":"","re​​commendations":""createdDate":"2019-07-16T02:48:34.786Z","alcrApprovalDeadline":"2019-07-19T02:48:59.000Z","dueDate":"2019-07-22T02:48:59.000Z ","chemicalAdvisorComments":"","re​​commendationsStripped":"Training Test","workStatus":"Pending-ALCRApproval","actionTakenStripped":"","re​​commendations":""createdDate":"2019-07-16T02:48:34.786Z","alcrApprovalDeadline":"2019-07-19T02:48:59.000Z","dueDate":"2019-07-22T02:48:59.000Z ","chemicalAdvisorComments":"","re​​commendationsStripped":"Training Test","workStatus":"Pending-ALCRApproval","actionTakenStripped":"","re​​commendations":"建议“:”建议“:”

训练测试

","tier":"6","cancelationComments":"","priority":"5","woSubmitted":false,"daysTillActionItemDue":"","eventStartDate":"2019-07-16T02:48 :37.276Z","assignedTo":"","currentCommentsStripped":"","fsActionItemNearDueDate":"1970-01-01T00:00:00.000Z","cancelDate":"1970-01-01T00:00:00.000 Z","averageBoed":374,"fsActionItemPastDueDate":"1970-01-01T00:00:00.000Z","lpoUom":"每天桶数","lpoRate":374,"surfaceWorkRequired":false,"liftMethod ":"ESP","originatorCai":"alwo.coeesp","actionItemNearDueDate":"2019-07-21T02:48:59.000Z","createdBy":"Centaur COE ESP","priorityRangeMin":250.000000000,"functionalGroup":"ESP COE"}]

(以上是一条记录的编辑 JSON)

uri = "https://quantprice.herokuapp.com/api/v1.1/scoop/period?tickers=MSFT&begin=2012-02-19"
webRequest = HttpWebRequest.Create(uri)
response = webRequest.GetResponse()
from System.IO import StreamReader
from System.Web.Script.Serialization import JavaScriptSerializer
streamReader = StreamReader(response.GetResponseStream())
jsonData = streamReader.ReadToEnd()
js = JavaScriptSerializer()
dataDict = js.Deserialize(jsonData,object)


# build a string representing the data in tab-delimited text format
myColName = []  
for val in dataDict["stations"]:
    myColName.append(val["id"])
textData =     "\t".join(myColName) + "\r\n"
print textData

for quote in dataDict["stations"]:
    print "\t".join(str(val) for val in quote)
    textData += "\t".join(str(val) for val in quote) + "\r\n"

print textData

如果我这样做,我的结果集将 [列名,列值] 显示为行。但是,我希望“列名”作为我的标题列表,“列值”作为我的行。

标签: jsonironpythonspotfire

解决方案


推荐阅读