【发布时间】:2016-04-04 10:27:44
【问题描述】:
我的javascript代码是这样的:
var emotions = {};
$('#emotions').children('#emotionFields').each(function(){
emotions[$(this).find($('.emotion')).val()]=$(this).find($('.value')).val()
});
$.ajax({
url: '../data',
dataType: 'json',
type: 'GET',
data: {action: 'dosomething',word:word,emotions:emotions},
success:function(response){
//something
},
error:function(msg){
//somethin
}
});
所以就在 ajax 调用之前,我的情绪对象看起来像这样:
emotions: Object
excitement: "value1"
guilt: "value2"
当我从 djangos request.GET 读取这些数据时,我看到了
{u'action': u'dosomething',
u'emotions[excitement]': u'value1',
u'emotions[guilt]': u'value2',
u'word': u'word'}
现在,如何将其转换为合适的字典,以便我可以访问兴奋和内疚?
【问题讨论】:
标签: json django python-2.7 django-models django-1.8