ios - What is the best method to break this into usable strings -


whats best way parse out?

string: umversion=2.9&umstatus=approved&umauthcode=152058&umrefnum=59567592&umavsresult=address%3a%20match%20%26%205%20digit%20zip%3a%20match&umavsresultcode=yyy&umcvv2result=match&umcvv2resultcode=m&umresult=a&umvpasresultcode=&umerror=approved&umerrorcode=00000&umcustnum=&umbatch=1&umbatchrefnum=91016&umisduplicate=n&umconvertedamount=&umconvertedamountcurrency=840&umconversionrate=&umcustreceiptresult=no%20receipt%20sent&umprocrefnum=&umcardlevelresult=a&umauthamount=10&umfiller=filled

i web service 1 big long string. each of variables listed have a = sign need populate variable with.

i need of data variables check them.

so, how should go breaking down.

use kind of code:

nsarray* components = [verylongstring componentsseparatedbystring:@"&"]; // array of strings "x=y" nsmutabledictionary* parsedresult = [nsmutabledictionary new]; (nsstring* keyvaluepair in components) {   nsarray* keyandvalue = [keyvaluepair componentsseparatedbystring:@"="];   nsstring* key = keyandvalue[0];   nsstring* value = (keyandvalue.count>1) ? keyandvalue[1] : nil;   // remove percent escapes in case have url-encoded characters in value '%20' ,   parsedresult[key] = [value stringbyreplacingpercentescapesusingencoding:nsutf8stringencoding] ?: [nsnull null]; }  nslog(@"dictionary of parameters: %@", parsedresult); 

you end dictionary containing keys , values extracted string.


Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -