JSON数据在IOS中无法正常运行

时间:2016-05-18 10:17:02

标签: ios iphone json swift

我使用URL从JSON获取数据。 JSON数据非常完美 JSON DATA code

但是当我用来从json数据中获取值时,它给了我null值。 我也试过podfile(SwiftyJSON),但仍然没有得到任何结果。 使用SwiftyJSON的代码

 let url: NSURL = NSURL(string: "http://einvito.com/login.php")!

      //  let url: NSURL = NSURL (string: "http://api.geonames.org/weatherIcaoJSON?ICAO=LSZH&username=demo")!
        let request:NSMutableURLRequest = NSMutableURLRequest(URL:url)
        let bodyData = "mobile=8401405853 & password=shivam"
        request.HTTPMethod = "POST"
        request.HTTPBody = bodyData.dataUsingEncoding(NSUTF8StringEncoding);

        let task = NSURLSession.sharedSession().dataTaskWithRequest(request)
        {
            data, response, error in

            if error != nil
            {
                print("error=\(error)")
                return
            }

            // You can print out response object
            print("response = \(response)")


            do {

             // var anyObj = try NSJSONSerialization.JSONObjectWithData(data!, options: NSJSONReadingOptions()) as AnyObject

                let json = JSON(data: data!)
                print(json) // Print JSON Data (Snap is there)
               let namenew  = json ["info"]["notusernumbers"]["userid"].stringValue
                print(namenew) // Print Nothing (Means null value got)

0 个答案:

没有答案