json - 使用 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":"","recommendationsStripped":"Training Test","workStatus":"Pending-ALCRApproval","actionTakenStripped":"","recommendations":""createdDate":"2019-07-16T02:48:34.786Z","alcrApprovalDeadline":"2019-07-19T02:48:59.000Z","dueDate":"2019-07-22T02:48:59.000Z ","chemicalAdvisorComments":"","recommendationsStripped":"Training Test","workStatus":"Pending-ALCRApproval","actionTakenStripped":"","recommendations":""createdDate":"2019-07-16T02:48:34.786Z","alcrApprovalDeadline":"2019-07-19T02:48:59.000Z","dueDate":"2019-07-22T02:48:59.000Z ","chemicalAdvisorComments":"","recommendationsStripped":"Training Test","workStatus":"Pending-ALCRApproval","actionTakenStripped":"","recommendations":"建议“:”建议“:”
训练测试
","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
如果我这样做,我的结果集将 [列名,列值] 显示为行。但是,我希望“列名”作为我的标题列表,“列值”作为我的行。
解决方案
推荐阅读
- java - 在android studio中使变量倒计时x时间
- woocommerce - 在 Woocommerce 中显示平均评分时避免 NAN 结果错误
- node.js - Blubird catch 中的自定义错误扩展类不起作用
- android - Kotlin:将地图转换为任何对象
- apache-kafka - 每次轮询之间的延迟时间是多少
- xml - 如何在 FXML/XML 中表示幂和指数,例如 Unicode 字符“上标二”?
- javascript - 多个标记在我的本地服务器上工作,但标记在我的实时站点上不起作用。http://www.sierracrestweb.com/dev/
- excel - 在 Excel 中保存 .csv 会转换为 .tsv
- android - 数据绑定是否会将 UI 逻辑移出布局?
- c# - 直接在桌面上“放置”一个 WinForm