Ябло (Свежее) / Говнокод #25705 Ссылка на оригинал

0

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  10. 10
  11. 11
  12. 12
  13. 13
  14. 14
  15. 15
  16. 16
  17. 17
  18. 18
  19. 19
/* Create a JSON object from JSON data stream. The stream should be opened and configured. All other behavior of this method is the same as the JSONObjectWithData:options:error: method.
     */
open class func jsonObject(with stream: InputStream, options opt: ReadingOptions = []) throws -> Any {
    var data = Data()
    guard stream.streamStatus == .open || stream.streamStatus == .reading else {
         fatalError("Stream is not available for reading")
     }
     repeat {
         var buffer = [UInt8](repeating: 0, count: 1024)
         var bytesRead: Int = 0
         bytesRead = stream.read(&buffer, maxLength: buffer.count)
         if bytesRead < 0 {
             throw stream.streamError!
         } else {
             data.append(&buffer, count: bytesRead)
         }
     } while stream.hasBytesAvailable
     return try jsonObject(with: data, options: opt)
}

Потоковое чтение JSON от авторов "iСделаль"

Запостил: Desktop Desktop, (Updated )

Комментарии (23) RSS

Добавить комментарий

Из-за тебя ушел bormand, guest!

    А не использовать ли нам bbcode?


    8