使用 mochijson2 解码 JSON 数据后,我得到了这个结构化的 proplist。
{struct,
[{<<"query">>,
{struct,
[{<<"count">>,4},
{<<"created">>,<<"2013-11-08T18:33:07Z">>},
{<<"lang">>,<<"en-US">>},
{<<"results">>,
{struct,
[{<<"quote">>,
[{struct,
[{<<"symbol">>,<<"YHOO">>},
{<<"Ask">>,<<"32.99">>},
{<<"AverageDailyVolu"...>>,<<"18383000">>},
{<<"Bid">>,<<"32.98">>},
{<<"AskRealt"...>>,<<"32.9"...>>},
{<<"BidR"...>>,<<...>>},
{<<...>>,...},
{...}|...]},
正如您在上面看到的,我想访问 [{struct, [{<<"symbol">>,<<"YHOO">>}]] ... 等,然后开始从那里提取数据。这就是我已经走了多远,但我似乎无法摆脱它。任何帮助表示赞赏!
Struct = mochijson2:decode(Body), Struct,
{struct, JsonData} = Struct,
{struct, Symbol} = proplists:get_value(<<"query">>, JsonData),
{struct, New} = proplists:get_value(<<"results">>, Symbol),
{struct, New1} = proplists:get_value(<<"quote">>, New),
Id = proplists:get_value(<<"symbol">>, New1),
Id.