Advertisement
drsgon13

 JSONDecode 2

Jun 11th, 2024 (edited)
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.49 KB | None | 0 0
  1. if aStream == inputStream {
  2. var dataBuffer = Array<UInt8>(repeating: 0, count: 1024)
  3. var len: Int
  4. while (inputStream?.hasBytesAvailable)! {
  5. len = (inputStream?.read(&dataBuffer, maxLength: 1024))!
  6. if len > 0 {
  7. let output = String(bytes: dataBuffer, encoding: .utf8)
  8. if nil != output {
  9. // print("server said: \(output ?? "")")
  10. // isOnlinePresented = true
  11. let msg = output
  12. let msgTest = msg!.split(separator: ";")
  13. let str2 = msg!.replacingOccurrences(of: msgTest[0]+";", with: "")
  14. let str3 = str2.replacingOccurrences(of: " ", with: "")
  15. print(str3)
  16. let data = Data(str3.utf8)
  17.  
  18. do {
  19. // make sure this JSON is in the format we expect
  20. let json = try JSONSerialization.jsonObject(with: data)
  21. print(json)
  22. } catch let error as NSError {
  23. print("Failed to load: \(error.localizedDescription)")
  24. }
  25. }
  26. }
  27. }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement