[英]Get the result of AFNetworking response as JSON string array
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. 我一直在尝试从Web服务中获取作为字符串数组的响应数据,但是我无法做到这一点,Alamofire无法正常工作,这就是为什么要使用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 可选(“ Array \\ n(\\ n [0] => Array \\ n(\\ n [name] => Apple Juice \\ n [0] => Apple Juice \\ n)\\ n \\ n [1] => Array \\ n(\\ n [名称] => Apple Juice \\ n [0] => Apple Juice \\ n)\\ n \\ n [2] =>阵列\\ n(\\ n [name] => DryClean \\ n [0] = > DryClean \\ n)\\ n \\ n [3] =>阵列\\ n(\\ n [name] => DryClean \\ n [0] => DryClean \\ n)\\ n \\ n)\\ n
\\n Warning : json_decode() expects parameter 1 to be string, array given in /home/thegapps/public_html/abualrob/HotelsSysAPI/index.php on line 150 \\ n 警告 :json_decode()期望参数1为字符串,在第150行的/home/thegapps/public_html/abualrob/HotelsSysAPI/index.php中给出的数组
\\n") \\ 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 AFNetworing会将JSON解析为字典并使用
NSArray *dictArr = responseObject[@"mydata"];
My suggestion u should 我的建议你应该
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.