Mojo 的轻量级 JSON 解析库。
开源地址:https://github.com/bgreni/EmberJson
它的简单示例:
from ember_json import *
var s = '{"key": 123}'
var json = JSON.from_string(s)
print(json["key"].int()) # prints 123
json = JSON.from_string('[123, "foo"]')
print(json[1].string()) # prints foo
用法:
from ember_json import *
fn main() raises:
# parse string
var s = '{"key": 123}'
var json = JSON.from_string(s)
print(json.is_object()) # prints true
# fetch inner value
var ob = json.object()
print(ob["key"].int()) # prints 123
# implicitly access json object
print(json["key"].int()) # prints 123
# json array
s = '[123, 456]'
json = JSON.from_string(s)
var arr = json.array()
print(arr[0].int()) # prints 123
# implicitly access array
print(json[1].int()) # prints 456
# `Value` type is formattable to allow for direct printing
print(json[0]) # prints 123