问题描述
我正在创建一个任务,其中http请求拉动了天气,这就是我到目前为止所要做的:
<TaskerData sr="" dvi="1" tv="5.10.1">
<Task sr="task79">
<cdate>1494395940378</cdate>
<edate>1604394719692</edate>
<id>79</id>
<nme>Create Weather Alert</nme>
<pri>100</pri>
<Action sr="act0" ve="7">
<code>547</code>
<Str sr="arg0" ve="3">%json</Str>
<Str sr="arg1" ve="3"> </Str>
<Int sr="arg2" val="0"/>
<Int sr="arg3" val="0"/>
<Int sr="arg4" val="0"/>
<Int sr="arg5" val="3"/>
</Action>
<Action sr="act1" ve="7">
<code>339</code>
<Bundle sr="arg0">
<Vals sr="val">
<net.dinglisch.android.tasker.RELEVANT_VARIABLES><StringArray sr=""><_array_net.dinglisch.android.tasker.RELEVANT_VARIABLES0>%http_file_output
File Output
Will always contain the file's full path even if you specified a directory as the File to save.</_array_net.dinglisch.android.tasker.RELEVANT_VARIABLES0><_array_net.dinglisch.android.tasker.RELEVANT_VARIABLES1>%http_response_code
Response Code
The HTTP Code the server responded</_array_net.dinglisch.android.tasker.RELEVANT_VARIABLES1><_array_net.dinglisch.android.tasker.RELEVANT_VARIABLES2>%http_cookies
Cookies
The cookies the server sent in the response in the Cookie:COOKIE_VALUE format. You can use this directly in the 'Headers' field of the HTTP Request action</_array_net.dinglisch.android.tasker.RELEVANT_VARIABLES2><_array_net.dinglisch.android.tasker.RELEVANT_VARIABLES3>%http_headers()
Response Headers
The HTTP Headers the server sent in the response. Each header is in the 'key:value' format</_array_net.dinglisch.android.tasker.RELEVANT_VARIABLES3><_array_net.dinglisch.android.tasker.RELEVANT_VARIABLES4>%http_response_length
Response Length
The size of the response in bytes</_array_net.dinglisch.android.tasker.RELEVANT_VARIABLES4></StringArray></net.dinglisch.android.tasker.RELEVANT_VARIABLES>
<net.dinglisch.android.tasker.RELEVANT_VARIABLES-type>[Ljava.lang.String;</net.dinglisch.android.tasker.RELEVANT_VARIABLES-type>
</Vals>
</Bundle>
<Int sr="arg1" val="0"/>
<Int sr="arg10" val="0"/>
<Int sr="arg11" val="0"/>
<Str sr="arg2" ve="3">http://api.openweathermap.org/data/2.5/forecast?lat=54.5234936&lon=-1.3049079&appid=<----APIKEY---->&units=metric&cnt=5</Str>
<Str sr="arg3" ve="3"/>
<Str sr="arg4" ve="3"/>
<Str sr="arg5" ve="3"/>
<Str sr="arg6" ve="3"/>
<Str sr="arg7" ve="3">Download/weather.json</Str>
<Int sr="arg8" val="30"/>
<Int sr="arg9" val="0"/>
</Action>
<Action sr="act2" ve="7">
<code>417</code>
<Str sr="arg0" ve="3">Download/weather.json</Str>
<Str sr="arg1" ve="3">%json</Str>
</Action>
<Action sr="act3" ve="7">
<code>548</code>
<Str sr="arg0" ve="3">%json</Str>
<Int sr="arg1" val="1"/>
</Action>
<Action sr="act4" ve="7">
<code>129</code>
<Str sr="arg0" ve="3">var parsedjson=JSON.parse(global('json'));
setLocal('test',parsedjson.cod);
flashLong(local('test'));</Str>
<Str sr="arg1" ve="3"/>
<Int sr="arg2" val="1"/>
<Int sr="arg3" val="45"/>
</Action>
<Action sr="act5" ve="7">
<code>548</code>
<on>false</on>
<Str sr="arg0" ve="3">%parsedjson</Str>
<Int sr="arg1" val="1"/>
</Action>
<Action sr="act6" ve="7">
<code>129</code>
<on>false</on>
<Str sr="arg0" ve="3">var test="test";</Str>
<Str sr="arg1" ve="3"/>
<Int sr="arg2" val="1"/>
<Int sr="arg3" val="45"/>
</Action>
<Action sr="act7" ve="7">
<code>548</code>
<Str sr="arg0" ve="3">%test</Str>
<Int sr="arg1" val="1"/>
</Action>
<Img sr="icn" ve="2">
<nme>hl_aaa_ext_sun</nme>
</Img>
</Task>
</TaskerData>
%json变量填充为:
{
"cod": "200","message": 0,"cnt": 1,"list": [
{
"dt": 1604394000,"main": {
"temp": 5.69,"feels_like": 1.68,"temp_min": 5.69,"temp_max": 5.99,"pressure": 1011,"sea_level": 1011,"grnd_level": 1008,"humidity": 81,"temp_kf": -0.3
},"weather": [
{
"id": 802,"main": "Clouds","description": "scattered clouds","icon": "03d"
}
],"clouds": {
"all": 49
},"wind": {
"speed": 3.5,"deg": 196
},"visibility": 10000,"pop": 0,"sys": {
"pod": "d"
},"dt_txt": "2020-11-03 09:00:00"
}
],"city": {
"id": 2636005,"name": "Thornaby","coord": {
"lat": 54.52,"lon": -1.3
},"country": "GB","population": 22356,"timezone": 0,"sunrise": 1604387520,"sunset": 1604420727
}
}
var parsedjson=JSON.parse(global('json'));
setLocal('test',parsedjson.cod);
flashLong(local('test'));
不仅flashLong并没有做任何事情,而且当任务(闪存)的最后一步运行时,我只会看到“%test”。
还可以肯定地说,我想从json中获取“ temp”,常规语法适用吗?
parsedjson.list[0].main.temp
任何人都可以帮助我了解为什么未按我的意愿填写%test吗?
免责声明:我了解自动工具。但是我更喜欢这样做,因为我不使用自动工具做其他事情。
解决方法
Taskers 的全局变量以第一个大写字母开头。应该是:var parsedjson=JSON.parse(global('json'));