0
我试图转换这是我从一个GET请求接收到一个可用的数组或类似这样的处理嵌套的JSON数组迅速
JSON数据我收到看起来像这样
{
"elementlist":{
"Ready Position":{
"Neutral Grip":["1,2,3,4,5"],"
Back Straight (Concave ir Convex?)":["1,2,3,4,5"],"
Body Low & Feet a little more than sholder width apart":["1,2,3,4,5"],"
Weight on Balls of Feet":["1,2,3,4,5"],"
Head Up":["1,2,3,4,5"],"
Sholder Blades Close":["1,2,3,4,5"],"
Eyes Drilled":["1,2,3,4,5"]
},
"Split Step":{"
Ready Position Conforms":["Yes,No"],"
Body Position Low":["1,2,3,4,5"],"
Legs Loaded/Prepared":["1,2,3,4,5"]
}
}
}
东西一些JSON数据
这是我使用
let playerAPIurl = "http://linkcoachuat.herokuapp.com/api/v1/session/element?organisation=5&group=green&sport=tennis"
var request = URLRequest(url: URL(string: playerAPIurl)!)
request.httpMethod = "GET"
let configuration = URLSessionConfiguration.default
let session = URLSession(configuration: configuration, delegate: nil, delegateQueue: OperationQueue.main)
let task = session.dataTask(with: request) { (data, response, error) in
if error != nil {
print("ERROR")
}
else{
do{
print("hello")
let myJson = try JSONSerialization.jsonObject(with: data!, options: []) as? [String: Any]
// Convert myJson into array here
print(myJson)
}
catch
{
}
}}
迅疾我想什么,能够做的就是嵌套数组的名称数组所以elementarray =“准备位置”,“分步”]和然后就可以说myJson [elementarray [0]或类似的东西来访问阵列
IM有点迅速小白所以任何帮助表示赞赏,请试着解释的答案,使他们易于理解
感谢您的帮助
我正在一个错误的第一行代码说“上下文类型[[String:Any]]不能与字典文字一起使用 – Ray
我编辑了该行,只需删除括号之间的”:“ – Woof