当我使用ajax帖子到我的api时,我收到了波纹管信息,我没有看到这种数据类型,谁能解释一下:
{
u'params[memory_cpu_address][3][cpu]': u'1\u6838',
u'params[bandwidth][bandwidth]': u'1M',
u'params[security_setting][example_name]': u'lasd01',
u'params[memory_cpu_address][2][model]': u'\u6807\u51c6\u578b\u4e00',
u'params[server_count][server_length]': u'1\u53f0',
u'params[operating_system][system_edition]': u'Windows2003',
u'params[memory_cpu_address][0][address]': u'\u6df1\u5733',
u'params[security_setting][user_name]': u'root',
u'params[storage][data_disk][disk_length]': u'0',
u'params[storage][system_disk][type]': u'SSD',
u'params[security_setting][user_password]': u'lasd01',
u'params[memory_cpu_address][4][memory]': u'1G',
u'params[total_prices][prices]': u'430',
u'params[memory_cpu_address][1][usable-area]': u'\u6df1\u5733\u4e00\u533a',
u'params[operating_system][system_name]': u'Windows',
u'params[storage][data_disk][type]': u'SSD',
u'params[time_buying][deta_time]': u'1\u6708',
u'params[storage][system_disk][disk_length]': u'40'
}
我的ajax代码是:
$.ajax({
type:'post',
url:'/app_api/buy_server/',
data:{'params':buy_data}, # buy_data is a dictionary in js
success:success_func,
})
我的views.py代码是:
if request.method == 'POST':
post_querydict = request.POST
post = post_querydict.dict()
print (post)
如何获得正常的字典格式?因为这种类型的数据,我无法获得像post.get("params")
方法那样的数据。
答案 0 :(得分:1)
将您的数据作为JSON发送,并在Python中反序列化。
$.ajax({
type: 'post',
url: '/app_api/buy_server/',
contentType: 'application/json',
data: JSON.stringify({'params':buy_data}),
success: success_func,
})
...
post_data = json.loads(request.body)
print(post_data)