接口json入参,不同类型参数格式
1、String
入参:A(String),B(String)
格式:{"A":"值a","B":"值b"}
示例:
接口测试入参这么填写:
{ "message": "值a", "data": "值b" }
注:参数值要用英文双引号""
2、Number
入参:A(Number),B(Number)
格式:{"A":值a,"B":值b}
示例:
接口测试入参这么填写:
{
"page": 值a,
"page_size": 值b
}
注:参数值不需要用英文双引号''"
3、Object
入参:
A(Object)
a1(Number)
a2(Number)
格式:
{"A":{"a1":值1,"a2":值2}}
示例:
接口测试入参这么填写:
{"data": { "page": 值1, "page_size": 值2} }
注:a1,a2是入参A(Object)的下一级,Object类型的入参,需要用{}把参数值括起来
4、Array
入参:
A(Array)
a1(String)
a2(Number)
格式:
{"A":[{"a1":值1,"a2":值2}]}
示例:
接口测试入参这么填写:
{"data":[ { "page": "值1", "page_size": 值2}] }
注:a1,a2是入参A(Array)的下一级,Array类型的入参,需要用[]把参数值括起来
5、Boolean
入参:A(Boolean),B(Boolean)
格式:{"A":"true","B":"false"}
示例:
接口测试入参这么填写:
{ "A": true, "B": false }
扩展1:
1、Object类型入参,有多个值
有两条数据a,b要传入
应该这样:
{
"list":{
{"page":"数据1","pagesize":1},
{"page":"数据2","pagesize":2}
}
}
2、Array类型入参,有多个值
有两个学生a,b要传入
应该这样:
{
"student":[
{"name":"学生a","age":1},
{"name":"学生b","age":2}
]
}
3、扩展
{ "string|1-10": "★", "number|1-100": 1, "boolean|1-2": true, "regexp": "/[a-z][A-Z][0-9]/", "function": "() => Math.random()", "array|1-10": [ { "foo|+1": 8, "bar|1-10": "★" } ], "items": [ 1, true, "hello", "/\\w{10}/" ], "object": { "foo|+1": 2, "bar|1-10": "★" }, "placeholder": "@title" }