星期六, 8月 07, 2021

[Eggplant] SenseTalk JSON資料操作

JSON已經是普遍的資料交換標準,可以簡單跟不同程式間作為溝通的橋樑。

SenseTalk提供JSONFormat/JSONValue二個方法來讓用戶使用

JSONValue

將json string轉換到json object於sensetalk使用

PS:要注意json字串要有雙引號,否則會解析錯誤

MockDataFromExcel "PM","ETS_PM_0008"

put the result into mockTicket

log mockTicket

put JSONValue(mockTicket) into ticketInfoWithJSON

log ticketInfoWithJSON's reserveNo



2021/8/8, 2:36:12 PM Log {"carType":"標準車廂", "count":"1", "date":"2021/07/30", "depature":"14:46", "end":"台中", "full":1, "fullSubTotal":"700", "no":"651", "reserveNo":"06264014", "seat":"window", "start":"台北", "subTotal":"TWD 700", "trainTimeType":">60", "type":"單程"}

2021/8/8, 2:36:12 PM Log 06264014


JSONFormat

put JSONFormat(ticketInfoWithJSON) into ticketInfoWithJSONString

log ticketInfoWithJSONString

當然也可以在把json object轉回string回存,中文也可以正常編碼

2021/8/8, 2:36:17 PM Log {

  "carType": "\u6a19\u6e96\u8eca\u5ec2",

  "count": "1",

  "date": "2021/07/30",

  "depature": "14:46",

  "end": "\u53f0\u4e2d",

  "full": 1,

  "fullSubTotal": "700",

  "no": "651",

  "reserveNo": "06264014",

  "seat": "window",

  "start": "\u53f0\u5317",

  "subTotal": "TWD 700",

  "trainTimeType": ">60",

  "type": "\u55ae\u7a0b"

}

沒有留言:

張貼留言

留個話吧:)