2017-01-24 6 views
1

私はalamofireとswiftyjsonを使ってそれを取得しています。私は文字列 "ubus_rpc_session"を取得する必要があります、私はこのようにtryedが、私は配列を取得、私は文字列を取得する必要があります。私たちを手伝ってくれますか?swiftyjsonがjsonアレイから文字列を取得しています

Alamofire.request(URL, method: .post, parameters: param, encoding: JSONEncoding.default).responseJSON { response in 
    switch response.result { 
    case .success(let value): 
     let json = JSON(value) 
     let token = json["result"].arrayValue.map({$0["ubus_rpc_session"].stringValue}) 
     print(token) 

{ "jsonrpc":"2.0", 
    "id":1, 
    "result":[ 
     0, 
     { 
     "ubus_rpc_session":"07e111d317f7c701dc4dfde1b0d4862d", 
     "timeout":300, 
     "expires":300, 
     "acls":{ 
      "access-group":{ 
       "superuser":[ 
        "read", 
        "write" 
       ], 
       "unauthenticated":[ 
        "read" 
       ] 
      }, 
      "ubus":{ 
       "*":[ 
        "*" 
       ], 
       "session":[ 
        "access", 
        "login" 
       ] 
      }, 
      "uci":{ 
       "*":[ 
        "read", 
        "write" 
       ] 
      } 
     }, 
     "data":{ 
      "username":"root" 
     } 
     } 
    ] 
} 

答えて

0

は試してみてください。この

//(自分の文書で)JSON配列から文字列の配列

let arrayNames = json["users"].arrayValue.map({$0["name"].stringValue}) 


if let tempArray = json["result"].arrayValue { 
     for item in tempArray { 
       print(item) 
      if let title = item["ubus_rpc_session"].string { 
      println(title) 
     } 

     } 
     } 

またはこの

let value = tempArray[1].dictionaryObject! 
         print(value["ubus_rpc_session"]!) 
をご確認の取得
+0

ありがとう、最初の方法は働いている –

関連する問題