Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
306 views
in Technique[技术] by (71.8m points)

不用$.param,JSON对象怎么序列化指定参数格式??

JSON对象

let params = {
  sportType:1
  attrs:[{"attr":2,"lableId":5},{"attr":2,"lableId":6}]
  ballAge:2
};

jquery序列化函数处理

let opt = $.param(params);

序列化后Http请求Url参数

图片描述

问题

后端接口需要这样的的参数格式,请教怎么构造??

url参数格式:"sportType=1&attrs[0].lableId=6&attrs[0].attr=2&ballAge=2"  
sportType:1
attrs[0].lableId:6
attrs[0].attr:2
attrs[1].lableId:5
attrs[1].attr:2
ballAge:2

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

let params = {
sportType:1,
attrs:[

{"attr":2,"lableId":5},
{"attr":2,"lableId":6}

],
ballAge:2
};

你这个不序列化就是后端要的格式


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...