我有最小最大变量,这是模型查询的结果
args.aggregate(Min('price'))
args.aggregate(Max('price'))
这样返回序列化的数据
return HttpResponse(json.dumps([{"maxPrice":args.aggregate(Max('price')),
"minPrice":args.aggregate(Min('price'))}]), content_type ='application/json')
结果看起来像这样:
minPrice = {
"price__min" = 110;
};
maxPrice = {
"price__max" = 36000;
};
并提取数据如下所示
...
success:^(AFHTTPRequestOperation *operation, id responseObject){
NSDictionary *elements = responseObject;
int minPrice = elements[0][@"minPrice"][@"price__min"];
}
问题:如何更改django / python代码以使Objective-C代码看起来像这样:
int minPrice = elements[@"minPrice"];
最佳答案
data = args.aggregate(minPrice=Min('price'), maxPrice=Max('price'))
return HttpResponse(json.dumps(data), content_type='application/json')
数据变量是带有“ minPrice”和“ maxPrice”键的字典。
关于python - Django将单独的变量序列化为JSON,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/28339794/