ios - Convert all values of Container into NSString -


i have problem communicate server. webserver expects parameters in json object string. every number , every boolean in every container needs string.

for example have nsdictionary full of key values (values kinds of types - numbers, arrays etc.). example:

{ "anexamplenumber":7e062fa, "anexampleboolean":0, "anexamplearrayofnumber":[17,4,8] } 

has become:

{ "anexamplenumber":"7e062fa", "anexampleboolean":"0", "anexamplearrayofnumber":["17","4","8"] } 

i tried standard nsjsonserializer doesn't give me option need. tried transform in dictionary manually string seems overhead. have hint me? maybe serializer or function convert objects in container strings?

(i assume mean nsjsonserializer, not nsserializer.)

i doubt you'll find pre-rolled solution this. it's not general problem. note, incorrect json, json serializers shouldn't it.

the best solution imo write code transform nsdictionary nsdictionary in form want. if want make generic solution, suspect custom nsdictionary walker iskindofclass: best bet. should work:

nsdictionary *mystringdictfordict(nsdictionary *dict); // forward decl if needed  nsarray *mystringarrayforarray(nsarray *array) {     nsmutablearray *result = [nsmutablearray new];     [array enumerateobjectsusingblock:^(id obj, nsuinteger idx, bool *stop) {         if ([obj iskindofclass:[nsarray class]]) {             [result addobject:mystringarrayforarray(obj)];         } else if ([obj iskindofclass:[nsdictionary class]]) {             [result addobject:mystringdictfordict(obj)];         } else {             [result addobject:[obj description]];         }     }];      return result; }  nsdictionary *mystringdictfordict(nsdictionary *dict) {     nsmutabledictionary *result = [nsmutabledictionary new];     [dict enumeratekeysandobjectsusingblock:^(id key, id obj, bool *stop) {        if ([obj iskindofclass:[nsarray class]]) {             result[key] = mystringarrayforarray(obj);         } else if ([obj iskindofclass:[nsdictionary class]]) {             result[key] = mystringdictfordict(obj);         } else {             result[key] = [obj description];         }     }];      return result; } 

Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -