Server side execute a SQL query (server is written in python) returns a json which looks like this:
return HttpResponse(json.dumps([{"data":output, "total":theResult}]), content_type ='application/json')
output
is a result return from inner method and is already serialized like this:
output = serializers.serialize('json',p_list,fields=('price','publishdate','size'))
Client side receive successfully the response, success:^(AFHTTPRequestOperation *operation, id responseObject)
using AFHTTPRequestOperationManager
and this is what responseObject
looks like in debug console (lldb)
po responseObject
<__NSCFArray 0x116fa6190>(
{
data = "[{\"pk\": 817, \"model\": \"xx\", \"fields\": { \"price\": \"3300\", \"publishdate\": \"2014-10-30T00:00:00\", \"size\": 35}}, {\"pk\": 2799, \"model\": \"xx\", \"fields\": { \"price\": \"6250\", \"publishdate\": \"2014-12-08T00:00:00\",\"size\": 0}}]";
total = (
381
);
}
)
in console po responseObject[0][@"data"][0]
prints the data array and p responseObject[0][@"total"][0]
print 381 as expected
The Problem:
- in code trying to cast
responseObject[0][@"total"][0]
into integer return a garbage number - casting
responseObject[0][@"data"][0]
intoNSArray*
and then trying to perform count or any other operation causes an exception:'NSInvalidArgumentException', reason: '-[__NSCFString count]: unrecognized selector sent to instance