swift json 解析库
- 完成 json 打印
- 完成 json 解析
let str = "{ \"a\":[8,9,10],\"c\":{\"temp\":true,\"say\":\"hello\",\"name\":\"world\"}, \"b\":10.2}"
print("json 字符串::\n\(str) \n")
do {
// 解析 json 字符串
let result = try parseJson(str: str)
print("\n返回结果::")
// 格式化 json 字符串
print(prettyJson(json: result))
} catch {
print(error)
}
结果输出:
json 字符串::
{ "a":[8,9,10],"c":{"temp":true,"say":"hello","name":"world"}, "b":10.2}
返回结果::
{
"a":[
8,
9,
10
],
"c":{
"temp":true,
"say":"hello",
"name":"world"
},
"b":10.2
}