0

假设我有一些中等复杂的 JSON,比如

{
    "revenue": 100,
    "products":[
            {"name": "Apple", "price": 50},
            {"name": "Banana", "price": 50}
    ]
}

显然这有点做作,但是使用 JsonLoader 将其映射到猪的最佳方法是什么。

我试过了

a = LOAD 'test.json' USING
    JsonLoader('revenue:int,products:[(name:chararray,price:int)]');

或者

a = LOAD 'test.json' USING
    JsonLoader('revenue:int,products:[{(name:chararray,price:int)]}');

但是,当我 时DUMP A,我得到(100,)了两者。

我也试过

a = LOAD '/json/complex.json'
    USING JsonLoader('revenue:int,products:[{name:chararray,price:int}]');

哪个错误ERROR 1200: <line 1, column 28> mismatched input 'chararray' expecting LEFT_PAREN

解析这个以备将来使用的最佳方法是什么?

谢谢

4

1 回答 1

1

为了后代,

a = LOAD 'test.json' USING
    JsonLoader('revenue:int,products:{(name:chararray,price:int)}');
于 2012-12-30T22:02:44.800 回答