这是我运行以下2条命令后得到的输出。
Wc = os:cmd("curl -s -k -X GET 'http://10.210.12.158:10065/iot/get/task_id?id=1'"),
WW = decode_json(Wc),
输出---
{ok,{obj,[{"status",200},
{"data",
[{obj,[{"id",1},
{"task",
<<"Turn on the bulb when the temperature is greater than 28 ">>},
{"working_condition",1},
{"depending_value",<<"Temperature">>},
{"device",<<" BulbOnly">>},
{"turning_point",28},
{"config_id",null}]}]}]}}
我想分别获取这些数据。
例如-任务=温度高于28时打开灯泡
那么,我该怎么做?
答案 0 :(得分:0)
返回的结构似乎返回一个任务列表,并且每个任务都是一个属性列表,您可以执行类似的操作
-module(test).
-export([input/0, get_tasks/1]).
input() ->
{ok,{obj,[{"status",200},
{"data",
[{obj,[{"id",1},
{"task",
<<"Turn on the bulb when the temperature is greater than 28 ">>},
{"working_condition",1},
{"depending_value",<<"Temperature">>},
{"device",<<" BulbOnly">>},
{"turning_point",28},
{"config_id",null}]}]}]}}.
get_tasks({ok, {obj, [_Status, {"data", Tasks}|_Tail]}}) ->
[ get_task_description(T) || T <- Tasks ].
get_task_description({obj, Proplist}) ->
proplists:get_value("task", Proplist).
在外壳中运行它时,您将获得:
1> test:get_tasks(test:input()).
[<<"Turn on the bulb when the temperature is greater than 28 ">>]