Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Json error: The data couldn’t be read because it isn’t in the correct format. #60

Closed
Gensjava opened this issue Jul 31, 2019 · 1 comment
Labels

Comments

@Gensjava
Copy link

Gensjava commented Jul 31, 2019

I get data from here jsonBody
How can I get a good format?
override func stompClient(client: StompClientLib!, didReceiveMessageWithJSONBody jsonBody: AnyObject?, withHeader header: [String : String]?, withDestination destination: String) {

Optional({
dateMessage = 1564591416932;
id = 3608;
idFeed = 3193;
idSender = 996;
linkPhotoAvatar = "https://s3.us-east-1.amazonaws.com/images-views/chat/1553479212385-1553479211398.jpg";
message = Test;
messageViewed = 0;
nameSender = "test3 test";
type = 0;
})
json error: The data couldn’t be read because it isn’t in the correct format.

@Gensjava
Copy link
Author

Gensjava commented Jul 31, 2019

I am sorry, I found a solution such as:

let jsonData = try JSONSerialization.data(withJSONObject: jsonBody as Any, options: .prettyPrinted)
            let reqJSONStr = String(data: jsonData, encoding: .utf8)
            
            print("JSON Body : \(reqJSONStr)")
            let jsonResponse = FeedsComments.deserialize(from: reqJSONStr) as! FeedsComments

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants