我一直在尝试从Web服务获取响应数据作为字符串数组但我无法做到这一点,Alamofire无法正常工作,这就是我使用AFNetworking的原因。显然响应回来但是在故障块中我会将其打印为字符串以显示其返回的数据,但是字符串不是字符串数组。
这是我的代码:
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)
}
}
以下是回复:
可选(“数组\ n(\ n [0] =&gt;数组\ n \ n(\ n [名称] =&gt; Apple Juice \ n [0] =&gt; Apple Juice \ n)\ n \ n [1] =&gt; 数组\ n(\ n [名称] =&gt; Apple Juice \ n [0] =&GT; Apple Juice \ n)\ n \ n [2] =&gt;数组\ n(\ n [名称] =&gt; DryClean \ n [0] =&gt; DryClean \ n)\ n \ n [3] =&GT;数组\ n(\ n [名称] =&gt; DryClean \ n [0] =&gt; DryClean \ n)\ n \ n)\ n \ n \ n 警告:json_decode()期望参数1是字符串,数组给出 /home/thegapps/public_html/abualrob/HotelsSysAPI/index.php on line 150
\ n“)
总之,我只需要将响应作为字符串数组。
答案 0 :(得分:0)
您最好提供数据。 AFNetworing将JSON解析为dict并使用类似
NSArray *dictArr = responseObject[@"mydata"];
我的建议你应该