ios - Url correct but the dictionary is null -
i have download data using json, url correct (tested on chrome) empty dictionary. did go wrong?
nslog(@"'url %@", stringurl); //correct nsurlrequest *request = [nsurlrequest requestwithurl:[nsurl urlwithstring:stringurl]]; nshttpurlresponse __autoreleasing *response = nil; nserror __autoreleasing *error = nil; nsdata *result = [nsurlconnection sendsynchronousrequest:request returningresponse:&response error:&error]; // result is: /* <280d0a0d 0a0d0a0d 0a0d0a0d 0a0d0a7b 22636f6d 6d6f6e22 3a7b2261 636b223a 224f4b22 2c226661 756c7443 6f646522 3a6e756c 6c2c2266 61756c74 53747269 6e67223a 6e756c6c 7d2c2274 6f74616c 223a3138 362c2270 61676522 3a312c22 .......*/ nsstring *str = [[nsstring alloc] initwithdata:result encoding:nsutf8stringencoding]; nslog(@" string %@", str); //the string correct sbjsonparser *parser = [[sbjsonparser alloc] init]; nslog (@"the parser %@", parser); //the parser <sbjsonparser: 0x8877400> nsdictionary *object = [parser objectwithdata: result]; nslog(@" dictionary %@", object);// dictionary null the result of string:
nsstring *str = [[nsstring alloc] initwithdata:result encoding:nsutf8stringencoding]; nslog(@" string %@", str); /* ({"common": {"ack":"ok", "faultcode":null, "faultstring":null}, "total":8, "page":1, "limit":15, "products":[{"name":"banane solidal biological - cartone/estero/2^ cat.", "code":"52436", "anabel":"264342000", "haspezzature":true, "pezzaturelist": [{"weight":700.000,"unit":"gr","formatted":"700gr"}], "disponible":true, "promotionimage":null}, {"name":"kiwi 105-120 ii^ vas 500gr", "code":"52094", "anabel":"393261000", "haspezzature":true, "pezzaturelist": [{"weight":500.000,"unit":"gr","formatted":"500gr"}], "disponible":true, "promotionimage":null}, ........ .........]});*/ i put formatting readable, in fact returned data on 1 line
there "(" , ")" @ starting , ending of json response when try cast in nsdictionary or nsarray, doesnt recognize , hence goes empty. parsed you'll need add this:
str = [[str stringbyreplacingoccurrencesofstring:@"(" withstring:@""] stringbyreplacingoccurrencesofstring:@")" withstring:@""]; before
sbjsonparser *parser = [[sbjsonparser alloc] init]; nslog (@"the parser %@", parser); //the parser <sbjsonparser: 0x8877400> nsdictionary *object = [parser objectwithdata: result]; nslog(@" dictionary %@", object);// dictionary null
Comments
Post a Comment