我正在创建一个由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
}
}我希望能够做的是从json中获得简单的值。我在这里试过了
var parsedjson=JSON.parse(global('json'));
setLocal('test',parsedjson.cod);
flashLong(local('test'));flashLong不仅什么也没做,当任务的最后一步(闪存)运行时,我只看到"%test“。
另外,为了确保,假设我想要从json中获取"temp“常规语法应用对吗?
parsedjson.list[0].main.temp谁能帮助我理解为什么%test没有像我想要的那样被填充?
免责声明:我知道autotools。但我更喜欢这样做,因为我不会使用自动工具做任何其他事情。
发布于 2021-01-17 06:28:30
任务人员的全局字母以第一个大写字母开头。应该是:
var parsedjson=JSON.parse(global('json'));
发布于 2021-08-21 17:40:53
我知道这需要一段时间,但对于任何可能遇到这一点的人来说-从5.12版本开始,tasker支持解析JSON,而不需要额外的包。
因此,要获取cod的值,只需简单地:
SetVariable:
Name: %test_var
To: %json.cod
Structured Output: Checked
要获取温度,请将变量设置为%json.list[0].main.temp
https://stackoverflow.com/questions/64660048
复制相似问题