updated examples for new api, sort of. should have done all of this on a branch

This commit is contained in:
alisdair sullivan 2010-05-27 16:24:31 -07:00
parent 60943446c0
commit 697d14135a
2 changed files with 5 additions and 11 deletions

View file

@ -34,11 +34,8 @@
decode(JSON) -> decode(JSON) ->
P = jsx:decoder({{jsx_parser, event}, []}, []), P = jsx:decoder({{jsx_parser, event}, []}, []),
try try
{Result, Rest} = P(JSON), {Result, _} = P(JSON),
case jsx:tail_clean(Rest) of Result
true -> Result
; _ -> throw(badarg)
end
catch catch
_:_ -> throw(badarg) _:_ -> throw(badarg)
end. end.
@ -68,7 +65,7 @@ event(end_array, [Array, Parent|Stack]) when is_list(Parent) ->
event(end_object, [Object]) -> event(end_object, [Object]) ->
[Object]; [Object];
event(end_array, [Array]) -> event(end_array, [Array]) ->
[Array]; [lists:reverse(Array)];
event({key, Key}, [Object|Stack]) -> event({key, Key}, [Object|Stack]) ->
[{key, Key}] ++ [Object] ++ Stack; [{key, Key}] ++ [Object] ++ Stack;

View file

@ -36,11 +36,8 @@ pretty(JSON, Opts) ->
Init = init(parse_opts(Opts, #opts{})), Init = init(parse_opts(Opts, #opts{})),
P = jsx:decoder({{jsx_prettify, jsx_event}, Init}, []), P = jsx:decoder({{jsx_prettify, jsx_event}, Init}, []),
try try
{Result, Rest} = P(JSON), {Result, _} = P(JSON),
case jsx:tail_clean(Rest) of Result
true -> Result
; _ -> throw(badarg)
end
catch catch
_:_ -> throw(badarg) _:_ -> throw(badarg)
end. end.