ios - Fill NSDictionary with JSON -


this question has answer here:

iam new in ios development . want fill json

"{     "form_name":"login_form_mobile",     "user_login":"mark wallet",     "password":"123456",     "dispatch":{"auth.login":"sign in"} } " 

into nsdictionary use in post url using afnetworking.

i fill dictionary this

nsdictionary *params = [nsdictionary dictionarywithobjectsandkeys:@"login_form_mobile",@"form_name",@"markwallet",@"user_login",@"123456",@"password",@"{ \" auth.login \" : \" sign in \" }",@"dispatch", nil]; 

now have 2 problems 1-the \" in before , after auth.login shown want show double quotes only. btw tried make nested dictionary solved first problem second 1 problem not. 2-when run app. , see how dictionary filled shown this

 {     dispatch = "{ \" auth.login \" : \" sign in \" }";     "form_name" = "login_form_mobile";     password = 123456;     "user_login" = markwallet; } 

a-there equal between key , value , need : not =
b-some words doesnt have "" password , 123456 , markwallet . dont know why
c-also dont know why dispatch , value go in first.

edit:

i used new code.

nsdictionary *dic = [[nsdictionary alloc]initwithobjectsandkeys:@"sign in",@"auth.login", nil];  nsarray *keys = [nsarray arraywithobjects:@"form_name",@"user_login",@"password",@"dispatch",nil];  nsarray *objects = [nsarray arraywithobjects:@"login_form_mobile",@"markwalletz",@"123456",dic,nil];  nsmutabledictionary * params1 = [[nsmutabledictionary alloc]init]; params1 = [nsmutabledictionary dictionarywithobjects:objects forkeys:keys]; 

but when see params1 value in debug

{     dispatch =     {         "auth.login" = "sign in";     };     "form_name" = "login_form_mobile";     password = 123456;     "user_login" = markwalletz; } 

and differs 1 need stated @ top of question , when send request dictionary replies bad request.

several things need understand:

  • when nslog nsdictionary, not display json syntax. yes, superficially looks json, but, noted, not character strings quoted (only blanks or odd characters quotes) , = used instead of :. because it's description of nsdictionary object, not json translation.
  • and, on other hand, because stuff looks same between json , nsdictionary not make same. "dispatch":{"auth.login":"sign in"} entry represents second nsdictonary value of key "dispatch". cannot create second dictionary making characters json/description representation. rather, have (as separate conceptual step) create one-element dictionary , insert object in outer dictionary.
  • one place nsdictionary , json are same neither nsdictionary nor json "object" maintains order of key/value pairs contains. don't expect see values in same order in 1 version vs other.

Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -