I have been trying to get the response data from the web service as array of strings but i couldn't manage to do that, Alamofire didn't work properly and thats why im using AFNetworking. apparently the response comes back but in the failure block and i will print it as string to show that its returning data but as string not as array of strings.
Here is my code :
let manager = AFHTTPRequestOperationManager()
manager.responseSerializer = AFJSONResponseSerializer(readingOptions: NSJSONReadingOptions.AllowFragments)
// manager.responseSerializer.acceptableContentTypes = NSSet(array: ["text/plain", "text/html", "application/json"]) as Set<NSObject>
manager.GET(url, parameters: nil, success: { (AFHTTPRequestOperation, ewsult) -> Void in
print("doing the request")
// print(AFHTTPRequestOperation)
// print()
}) { (operation, erropr) -> Void in
print(operation.responseString)
// print(erropr)
}
}
Here is the response :
Optional("Array\\n(\\n [0] => Array\\n (\\n [name] => Apple Juice\\n [0] => Apple Juice\\n )\\n\\n [1] => Array\\n (\\n [name] => Apple Juice\\n [0] => Apple Juice\\n )\\n\\n [2] => Array\\n (\\n [name] => DryClean\\n [0] => DryClean\\n )\\n\\n [3] => Array\\n (\\n [name] => DryClean\\n [0] => DryClean\\n )\\n\\n)\\n
\\n : json_decode() expects parameter 1 to be string, array given in on line :json_decode()期望参数1为字符串,在第行的给出的数组
\\n")
In summary i just need to get the response as array of strings.
u'd better provide the data. AFNetworing will parse the JSON to a dict and use like
NSArray *dictArr = responseObject[@"mydata"];
My suggestion u should
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.