【发布时间】:2018-02-05 04:16:19
【问题描述】:
我想像下面那样做。如何使用“SwiftyJSON”将JSON.Element 转换为JSON?
public func convert() -> String? {
let json :JSON = ["Animals" : ["dog","cat"], "Shop":"Tokyo"]
let animals = json["Animals"]
let repezentativeAnimal = animals.first
repezentativeAnimal!["Shop"] = json["Shop"] // Value of tuple type 'JSON.Element' (aka '(String, JSON)') has no member 'subscript'
// I want to return String below
// ["dog":"---", "Shop":"Tokyo"]
return repezentativeAnimal.rawString() // error : Value of type 'JSON.Element?' (aka 'Optional<(String, JSON)>') has no member 'rawString'
}
【问题讨论】:
-
我可能会在这方面为您提供帮助,但您能否更好地解释您想要实现的目标?返回这样的字符串:
["dog":"---", "Shop":"Tokyo"]完全没有意义 -
你说
I want to return String ["dog":"---", "Shop":"Tokyo"]但即使在修复你的代码后它也不会返回这个,它只会返回“狗”。你的问题不清楚。如果您将let repezentativeAnimal = animals.first替换为var repezentativeAnimal = animals.first!.1,您可以看到这一点...
标签: swift swift4 swifty-json