gpt4 book ai didi

json - 当变量在 Swift 中作为 AnyObject 传入时,字典键和值丢失引号 ("")

转载 作者:行者123 更新时间:2023-11-30 10:31:41 24 4
gpt4 key购买 nike

我正在 Swift 中创建一个 [String: AnyObject] 类型的字典,其中包含键:值对以及嵌套字典。每个项目都被转换为 AnyObject。但是,只有外部字典的键:值对在字符串两边带有引号(“”)。嵌套字典的键:值对一起丢失。我将整个嵌套字典转换为 AnyObject 元素。

let parameter: [String: AnyObject] = [
"cartonNumber": "\(cartonNumber)" as AnyObject,
"status": "DELIVERED" as AnyObject,
"documentNumbers":
[
"\"shipmentNumber\"": "\(currentShipmentNumber)",
"referenceNumber": "\(referenceNumber)",
"proNumber": "\(proNumber)",
"billOfLadingNumber": "\(bolNumber)",
"trackingNumber": "\(trackingNumber)"
] as AnyObject,
"sourceLocation": [
"plantCode":"1028"
] as AnyObject,
"targetLocation": [
"id":"73e64de9-36cd-4b20-be1d-13003e455008",
"type":"store/stores"
] as AnyObject,
"shipDate": "\(dateToday)" as AnyObject,
"items": [
"\"product\"": [
"gtin":"00004007334274"
],
"quantity": 2,
"documentNumbers":
[
"deliveryNumber": "\(deliveryNumber)"
],
] as AnyObject
]

希望在嵌套字典中的键:值周围保留引号

最佳答案

如果我在调试器中打印你的 JSON,我会得到这个输出。看来所有的“”都是正确的。您能解释一下您到底在尝试什么吗?

(lldb) po parameter
▿ 7 elements
▿ 0 : 2 elements
- key : "items"
▿ value : 3 elements
▿ 0 : 2 elements
- key : documentNumbers
▿ value : 1 element
▿ 0 : 2 elements
- key : deliveryNumber
- value : 7
▿ 1 : 2 elements
- key : "product"
▿ value : 1 element
▿ 0 : 2 elements
- key : gtin
- value : 00004007334274
▿ 2 : 2 elements
- key : quantity
- value : 2
▿ 1 : 2 elements
- key : "documentNumbers"
▿ value : 5 elements
▿ 0 : 2 elements
- key : proNumber
- value : 3
▿ 1 : 2 elements
▿ key : "shipmentNumber"
- value : 1
▿ 2 : 2 elements
- key : referenceNumber
- value : 2
▿ 3 : 2 elements
- key : trackingNumber
- value : 5
▿ 4 : 2 elements
▿ key : billOfLadingNumber
- value : 4
▿ 2 : 2 elements
- key : "shipDate"
- value : 6
▿ 3 : 2 elements
- key : "sourceLocation"
▿ value : 1 element
▿ 0 : 2 elements
- key : plantCode
- value : 1028
▿ 4 : 2 elements
- key : "targetLocation"
▿ value : 2 elements
▿ 0 : 2 elements
- key : type
- value : store/stores
▿ 1 : 2 elements
- key : id
▿ value : 73e64de9-36cd-4b20-be1d-13003e455008
▿ 5 : 2 elements
- key : "status"
- value : DELIVERED
▿ 6 : 2 elements
- key : "cartonNumber"
- value : 0

关于json - 当变量在 Swift 中作为 AnyObject 传入时,字典键和值丢失引号 (""),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59074122/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com