来自swift中JSON的变量

时间:2017-04-12 15:51:56

标签: json swift

我是一个初学者,快速的Progrmamming我需要来自JSON的值它看起来像这样......我不明白这个JSON .. :-(:

{

"nextUpdate":300,
"subscriptions":["speedon","roamLikeHome","tns"],
"title":"",
"hasOffers":true,
"passName":"Ihr Telekom Datentarif",
"passStage":1,
"validityPeriod":2,
"initialVolume":6547308544,
"initialVolumeStr":"6,09 GB",
"usedVolume":2550134551,
"usedPercentage":39,
"usedVolumeStr":"2,37 GB",
"usedAt":1487480985000,
"remainingSeconds":833168,
"remainingTimeStr":"9 Tage 15 Std.",
"downSpeed":-1,
"downSpeedStr":"Max",
"upSpeed":-1,
"upSpeedStr":"Max",
"passType":103


}

我将获得usedVolume& usedPercentage变量!

我的代码:

    var volume: [String] = []
    var percent: [String] = []

    override func viewDidLoad() {
        super.viewDidLoad()


        let url=URL(string:"http://pass.telekom.de/api/service/generic/v1/status/.json")
        do {
            let allData = try Data(contentsOf: url!)
            let data = try JSONSerialization.jsonObject(with: allData, options: JSONSerialization.ReadingOptions.allowFragments) as! [String : AnyObject]
            if let arrJSON = data["??"] {........

我如何在变量中获得它,百分比..

感谢您的帮助..!

1 个答案:

答案 0 :(得分:0)

试试这种方式。

var position =  {
  current: {
    coordinates: '2408,1822',
    name: 'start',
    premiumPoints: 0,
    points: 0,
    right: Projects.detectProjectByKeyword("moneymat").coordinates,
    left: Projects.detectProjectByKeyword("wohnung").coordinates,
    forward: Projects.detectProjectByKeyword("supermarkt").coordinates,
    backward: "0,0"
  },
  start: //more objects to check