SwiftyJSONLines

在 Swift 中处理 JSONLines 数据的更好方式。

安装

Swift 包管理器 (Swift Package Manager)

let package = Package(
    name: "MyPackage",
    products: [...],
    targets: [
        .target(
            "YouAppModule",
            dependencies: [
                .product(name: "SwiftyJSONLines", package: "SwiftyJSONLines")
            ]
        )
    ],
    dependencies: [
        .package(url: "https://github.com/fumito-ito/SwiftyJSONLines.git", .upToNextMajor(from: "0.0.1"))
    ]
)

用法

// You can parse and iterate json objects from jsonl format string.
let jsonlines = try JSONLines(jsonString)
for json in jsonlines.toDictionaries() {
    print(json) // => [String: Any] object
}

// Ofcourse, you can get json lines from data,
let jsonlinesFromData = try JSONLines(data: jsonStringData)

// local file...
let jsonlinesFromLocalPath = try JSONLines(contentsOfFile: "/path/to/example.jsonl")

// and remote file
let jsonlinesFromRemoteFile = try await JSONLines(contensOf: URL(string: "https://example.com/path/to/example.jsonl"))

贡献

欢迎提交 Pull Requests。对于重大更改,请先提出 issue 讨论您想要更改的内容。

请确保适当地更新测试。

许可证

Apache License 2.0