但是当我用来从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)