Closed NikunjRajyaguru closed 6 years ago
LSResponse only contains statusCode which is http status code, jsonObject which is the response payload in JSON format.
Hello,
@NikunjRajyaguru, did you manage to retrieve just some data from the Json? Like retrieve just the email in: { dateOfBirth = { day = 6; month = 6; year = 1996; }; emailAddress = "example@example.com"; firstName = Example; id = Fjv3f184Fm; }
Yes, I had successfully retrieved the data from response.
@NikunjRajyaguru Thank you, how did you manage to do this? Could you please post an example or explain? I'm new with swift
@NikunjRajyaguru hello, I did it! (:
For anyone who is doing the same question:
print("Request success User Linkedin ID: \(String(describing: response.jsonObject["id"]!))")
@tbalancin
As I'm away from my code but some how tried to find this. Hope may help. Below is the code which I had implemented
if LISDKSessionManager.hasValidSession() { LISDKAPIHelper.sharedInstance().getRequest("https://api.linkedin.com/v1/people/~?format=json", success: { (response) in print(response as Any) print(response?.data as Any) let data = response?.data.data(using: String.Encoding.utf8) do { let dictResponse : [String : AnyObject] = try JSONSerialization.jsonObject(with: data! as Data, options: JSONSerialization.ReadingOptions.mutableContainers) as! [String : AnyObject] print(dictResponse) if socialDelegate != nil { socialDelegate.getLinkedinResponse(userData: dictResponse) } } catch { print("error") } }, error: { (error) in print(error as Any) })
Here, I had replaced the response in method LISDKAPIHelper.sharedInstance().getRequest() of main SDK file i.e, from LSResponse to NSDictionary and fetching it in NSDictionary format then after using JSONSerialization.jsonObject, converted it to JSON format.
Hope you understand. Thanks,
I've parsed LSResponse using swift 4, small example is shown below:
let positionsDictionary:[String : Any] = response.jsonObject?["positions"] as! [String : Any]
let valuesArray: Dictionary<String, Any>.Values = positionsDictionary.values
let positionArray:[Any] = valuesArray.first as! [Any]
let positionDictionary:[String : Any] = positionArray.first as! [String : Any]
let jobTitle:String = positionDictionary["title"] as! String
let companyDictionary:[String : Any] = positionDictionary["company"] as! [String : Any]
let companyName:String = companyDictionary["name"] as! String
Here I just parsed user job title and company name.
Hi,
I successfully implemented this library into my project.
Now, the issue is that the response which I'm getting is in LSResponse format so how can I parse and get data from it.
Or else let me know any way to get data from this response i.e, LSResponse.
Thanks in advance.