单位换算大全接口支持的储存容量、时间和其他各物理单位的类型表。您可以通过该接口的第二个接入点支持类型列表来动态获取。如果您需要查询某一类型所支持换算的单位,则可以通过第三个接入点计量单位查询。该接口支持的类型会根据普用性不断补充,欢迎大家反馈。
支持单位:
| 类型 | 名称 |
|---|---|
| datastorage | 数据存储 |
| time | 时间 |
| pressure | 压力 |
| weight | 重量 |
| volume | 体积 |
| longness | 长度 |
| area | 面积 |
| power | 功率 |
| angle | 角度 |
| speed | 速度 |
| work | 做功 |
| farad | 法拉 |
| frequency | 频率 |
| temperature | 温度 |
接口信息
根据数值和单位进行换算,注意单位名称和数值范围
接口地址:https://apis.tianapi.com/convertunits/index
请求示例:https://apis.tianapi.com/convertunits/index?key=你的APIKEY&num=3&from=mb&to=kb&type=datastorage
支持协议:http/https
请求方式:get/post
返回格式:utf-8 json
请求参数
post方式请求时,enctype应为application/x-www-form-urlencoded
上传文件二进制数据流方式,enctype必须为multipart/form-data
参数url、base64中有特殊字符时,建议对值urlencode编码后传递
| 名称 | 类型 | 必须 | 示例值/默认值 | 说明 |
|---|---|---|---|---|
| key | string | 是 | 您自己的APIKEY(注册账号后获得) | API密钥 |
| num | float | 是 | 3 | 数值 |
| from | string | 是 | mb | 源单位 |
| to | string | 是 | kb | 转换单位 |
| type | string | 是 | datastorage | 类型 |
| round | int | 否 | 2 | 四舍五入,数字表示保留位数 |
返回数据:
{
"code": 200,
"msg": "success",
"result": {
"value": 3072,
"unit": "kb",
"type": "datastorage",
"tip": "normal"
}
}
代码参考:
# -*- coding: utf-8 -*-
import http.client, urllib, json
conn = http.client.HTTPSConnection('apis.tianapi.com') #接口域名
params = urllib.parse.urlencode({'key':'你的APIKEY','num':'3','from':'mb','to':'kb','type':'datastorage'})
headers = {'Content-type':'application/x-www-form-urlencoded'}
conn.request('POST','/convertunits/index',params,headers)
tianapi = conn.getresponse()
result = tianapi.read()
data = result.decode('utf-8')
dict_data = json.loads(data)
print(dict_data)

539

被折叠的 条评论
为什么被折叠?



