ios - Convert NSString to NSDictionary bug -


i have string server, , when try convert nsdictionary - "nil". when try write same nsstring myself - it's ok!

i server encoded string, use "aes256decryptwithkey" nsstring+aescrypt.h decrypt, , nsstring, string convert nsdata , try nsdictionary

nsstring *str = @"{\"error\":{\"password\":[\"error wrong!\"]}}"; //string written myself  nsdata *jsondata = [str datausingencoding:nsutf8stringencoding];     nsdictionary *json = [nsjsonserialization jsonobjectwithdata:jsondata                                                          options:kniloptions                                                            error:&error]; 

this code work, string server - not(

nsdata log (message server) - <7b226572 726f7222 3a7b2270 61737377 6f726422 3a5b22d0 9dd0b5d0 bfd180d0 b0d0b2d0 b8d0bbd1 8cd0bdd1 8bd0b920 656d6169 6c20d0b8 d0bbd0b8 20d0bfd0 b0d180d0 bed0bbd1 8c225d7d 7d000000>

nsdata log (my string) - <7b226572 726f7222 3a7b2270 61737377 6f726422 3a5b22d0 9dd0b5d0 bfd180d0 b0d0b2d0 b8d0bbd1 8cd0bdd1 8bd0b920 656d6169 6c20d0b8 d0bbd0b8 20d0bfd0 b0d180d0 bed0bbd1 8c225d7d 7d>

if nslog string server, - {"error":{"password":["error wrong!"]}} , string without "\"

then "po &error.localizeddescription" - error: address of property expression requested error: 1 errors parsing expression

then "po error.localizeddescription" - printing description of error: error domain=nscocoaerrordomain code=3840 "the operation couldn’t completed. (cocoa error 3840.)" (garbage @ end.) userinfo=0x7f9940497550 {nsdebugdescription=garbage @ end.}

what can be??

the error message says:

garbage @ end.

so, comparing data , data server, see:

test string data: <7b226572 726f7222 3a7b2270 61737377  6f726422 3a5b22d0 9dd0b5d0 bfd180d0  b0d0b2d0 b8d0bbd1 8cd0bdd1 8bd0b920  656d6169 6c20d0b8 d0bbd0b8 20d0bfd0  b0d180d0 bed0bbd1 8c225d7d 7d>  server data: <7b226572 726f7222 3a7b2270 61737377  6f726422 3a5b22d0 9dd0b5d0 bfd180d0  b0d0b2d0 b8d0bbd1 8cd0bdd1 8bd0b920  656d6169 6c20d0b8 d0bbd0b8 20d0bfd0  b0d180d0 bed0bbd1 8c225d7d 7d000000> 

the decoded data 3 bytes longer. maybe padded ahead of encryption or effect of decryption due padding parameter. workaround remove stray 000000.


Comments

Popular posts from this blog

How has firefox/gecko HTML+CSS rendering changed in version 38? -

javascript - Complex json ng-repeat -

jquery - Cloning of rows and columns from the old table into the new with colSpan and rowSpan -