I am trying to send array to PHP script, but i can't detect this array on server side. I create php script that prints all REQUEST array. And for this code:
let mapDict = [ "var1":"First", "var2":"Second"]
do {
let jsonData = try NSJSONSerialization.dataWithJSONObject(mapDict, options: [])
// create post request
let url = NSURL(string: myURL)!
let request = NSMutableURLRequest(URL: url)
request.HTTPMethod = "POST"
// insert json data to the request
request.HTTPBody = jsonData
let task = NSURLSession.sharedSession().dataTaskWithRequest(request){
data,response,error in
if error != nil{
print(error!.localizedDescription)
return
}
let newData = NSString(data: data!, encoding: NSUTF8StringEncoding)
print(newData)
}
task.resume()
}
catch {
print (error)
}
In Xcode console I receive
Optional(Array
(
[{"var1":"First","var2":"Second"}] =>
)
What am i doing wrong?
p.s. if i add .PrettyPrinted i receive:
Optional(Array
(
[{
__"var1"_:_"First",
__"var2"_:_"Second"
}] =>
)
And i don't know - where are this "_:_" came from?