所以我有这个代码:
class JSONResponseJSONDumps(HttpResponse):
"""JSON response class."""
def __init__(self, obj='', json_opts={}, mimetype="application/json", *args, **kwargs):
content = json.dumps(obj, cls=DjangoJSONEncoder)
super(JSONResponseJSONDumps,self).__init__(content, mimetype, *args, **kwargs)
class Equipment(models.Model):
serial = models.CharField(max_length=64, blank=False)
volts = models.IntegerField(blank=True, null=True)
hertz = models.IntegerField(blank=True, null=True)
amps = models.IntegerField(blank=True, null=True)
//views.py
data = {
"serial": equipment.serial,
"hertz": equipment.hertz,
"volts": equipment.volts,
"amps" : equipment.amps,
}
response = JSONResponseJSONDumps(data, {}, 'application/json')
我将其发送回 iOS。现在,我遇到了一个奇怪的问题,安培作为整数发送,iOS 看到了这一点,在伏特和安培的情况下,它作为字符串发送?!
这在我的其他模型中也发生过。有任何想法吗?!
谢谢!