- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 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)
}
Desktop 07.07.2019 13:38 # 0
https://github.com/apple/swift-corelibs-foundation/blob/ef6f96ee82ea0f54252071c0ecadf5f01be9aecc/Foundation/JSONSerialization.swift#L208
KaBauHblu_nemyx 07.07.2019 19:51 # +1
BoeHHblu_nemyx 07.07.2019 20:43 # +1
guest8 07.07.2019 22:41 # −999
gost 07.07.2019 20:17 # +2
guest8 07.07.2019 20:34 # −999
guest8 07.07.2019 22:50 # −999
bormand 07.07.2019 22:55 # +2
И кавычки с учётом экранировок... В общем, пока пробежишься - оно уже почти и спарсится.
guest8 07.07.2019 22:57 # −999
KaBauHblu_nemyx 07.07.2019 23:24 # 0
guest8 07.07.2019 23:34 # −999
gost 07.07.2019 23:55 # 0
TEH3OPHblu_nemyx 08.07.2019 01:42 # 0
guest8 06.12.2019 05:56 # −999
XYPO3BO3 06.12.2019 14:14 # 0
BoeHHblu_nemyx 07.07.2019 20:43 # 0
Desktop 07.07.2019 21:42 # 0
guest8 08.07.2019 01:45 # −999
Desktop 08.07.2019 21:13 # 0
KaBauHblu_nemyx 08.07.2019 06:53 # 0
TEH3OPHblu_nemyx 08.07.2019 07:30 # 0
guest8 09.07.2019 00:18 # −999
guest8 09.07.2019 00:36 # −999