我正在尝试从以下JSON访问密钥:
{ items = ({a = “string for a”;b = “string for a”;c = “string for a”;},{a = “string for a”;b = “string for a”;c = “string for a”;},{a = “string for a”;b = “string for a”;c = “string for a”;});}
例如,我想获得第一个键' a'的值,但以下内容返回nil:
println(jsonResult["products[product_id]"]
答案 0 :(得分:1)
您的JSON示例无效。看看这个:
我会为Swift使用一个通用的JSON插件。例如:
然后使用:
let json : JSON = "your string"
用你的对象获取:
if let myproduct = json["products"]["productid"].array {
// content of your product (if array)
}