0

嗨,用 mochijson2 解码 JSON 后,我得到了这个结果(示例结果)

{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"...>>,<<...>>},
                    {<<...>>,...},
                    {...}|...]},

我现在正试图从变量“符号”、“询问”等中获取信息。但我不知道如何获取它们。我尝试使用 proplists 来做这件事,这就是我得到的结果:

{struct, JsonData} = Struct,
{struct, Ask} = proplists:get_value(<<"Ask">>, JsonData),
Key = proplists:get_value(<<"Ask">>, Ask),
Key.

感谢@legoscia 的帮助

4

1 回答 1

0

尝试这个:

{ok, {{_, 200, _}, _Headers, Body}} = httpc:request(get, {"http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20yahoo.finance.quotes%20where%20symbol%20in%20(%22YHOO%22%2C%22AAPL%22%2C%22GOOG%22%2C%22MSFT%22)%0A%09%09&env=http%3A%2F%2Fdatatables.org%2Falltables.env&format=json",[]},[],[]),

然后您将在Body变量中获得响应,这就是您需要传递给 mochijson 的内容。

于 2013-11-08T16:03:43.897 回答