提问人:grooot 提问时间:2/18/2021 最后编辑:grooot 更新时间:2/19/2021 访问量:31
如何在查询中合并 2 个 JSON
how to combine 2 json in query
问:
我需要附加 2 个 JSON。
目前,它打印为两个单独的 Json。
我如何结合我的两种阅读方式????我希望我的 Json 将两个读数放在一起。
let query = HKSampleQuery(sampleType: glucoseType!, predicate: predicate, limit: 5, sortDescriptors: nil) { (query, results, error) in
for result in results as! [HKQuantitySample] {
let bloodGlucose = result.quantity.description
let bloodGlucoseItem = HealthDataItem(endDate: result.endDate, value: String(bloodGlucose), startDate: result.endDate, type: .bloodGlucose)
let healthData = [bloodGlucoseItem]
do {
let data = try JSONEncoder().encode(healthData)
let json = String(data: data, encoding: String.Encoding.utf8)
for i in 0..<results!.count {
if (i != 0){
json!.append(json!)
}
print("json data:", json as Any )
}
resolve(json)
} catch {
//error handling
}
}
}
安慰:
json data: Optional("[{\"value\":\"8 mg\\/dL\",\"endDate\":635390040,\"startDate\":635390040,\"type\":\"bloodGlucose\"}]")
json data: Optional("[{\"value\":\"8 mg\\/dL\",\"endDate\":635390040,\"startDate\":635390040,\"type\":\"bloodGlucose\"}]
[{\"value\":\"8 mg\\/dL\",\"endDate\":635390040,\"startDate\":635390040,\"type\":\"bloodGlucose\"}]")
json data: Optional("[{\"value\":\"6 mg\\/dL\",\"endDate\":635393640,\"startDate\":635393640,\"type\":\"bloodGlucose\"}]")
json data: Optional("[{\"value\":\"6 mg\\/dL\",\"endDate\":635393640,\"startDate\":635393640,\"type\":\"bloodGlucose\"}]
[{\"value\":\"6 mg\\/dL\",\"endDate\":635393640,\"startDate\":635393640,\"type\":\"bloodGlucose\"}]")
答: 暂无答案
评论
healdData
append(contentsOf:)
enter()
leave()
notify()