如果我使用此网址: https://api.xively.com/v2/feeds/65673.json?datastreams=3
Xively返回:
{ "id":65673,
"title":"Swimming Pool",
"private":"false",
"tags":["arduino","xbee"],
"description":"Monitors swimming pool conditions",
"feed":"https://api.xively.com/v2/feeds/65673.json",
"status":"live",
"updated":"2013-08-03T22:35:27.489534Z",
"created":"2012-07-02T00:23:57.518294Z",
"creator":"https://xively.com/users/scott216",
"version":"1.0.0",
"datastreams":[{
"id":"3",
"current_value":"76.20",
"at":"2013-08-03T22:35:27.247712Z",
"max_value":"93.6","min_value":"-2845.0",
"tags":["Temp 1"],
"unit":{"symbol":"F","label":"Degrees"}
}],
"location":{
"disposition":"fixed",
"exposure":"outdoor",
"domain":"physical"
}
}
但是只想要current_value 76.20。有没有办法在URL中添加过滤器或其他内容,以便它只返回当前值?
答案 0 :(得分:0)
我假设您不打算使用JSON解析器,否则只需parsed_json['datastreams'][0]['current_value']
即可获得所需内容。
使用Xively API V2,您可以使用CSV格式,它更接近您想要的。
如您刚才所示,使用数据流过滤器检索Feed,但使用CSV:
GET https://api.xively.com/v2/feeds/65673.csv?datastreams=3
3,2013-08-05T09:18:01.566388Z,59.10
检索数据流本身:
GET https://api.xively.com/v2/feeds/65673/datastreams/3.csv
2013-08-05T09:18:01.566388Z,59.10
第一个示例仅在您在单个请求中获取多个数据流时才有意义,但您不希望所有这些数据流都被调用:
GET https://api.xively.com/v2/feeds/65673.csv?datastreams=1,2,3
如果您只想要一个数据流,则应使用第二个示例并使用逗号分割。