0

I have received response from the server.

I have stored that values in one string.

But my problem is in that string have some attribute values with & symbol its not an xml structure, so how can I get that attribute values in that string.

This is i am getting response from server. [Newlines have been added for clarity, it was all run together in one line -- editor]

&currency_code=USD
&currency_symbol$
&email_id=good@good.com
&usertypecode=ROBT
&id=fcscdj
&player_level=1
&player_isblocked=false
&lang=en
&respond=true
&flylogin=false
&str=PageEnd
&user_balance=100000394.90
&user_bonus_balance=0.00
&user_id=e4567

How can I get this values and show in label example currency code values in need to show in one label like USD in that label. Like that I need to do all dis email_id,usertypecode,player_isblocked

Please help me out This problem

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Balaji
  • 21
  • 4
  • 1
    Those "attribute values" look like HTTP request query parameters. Look at the accepted answer of this SO question for a possible solution: http://stackoverflow.com/questions/2225814/nsurl-pull-out-a-single-value-for-a-key-in-a-parameter-string – trojanfoe Aug 30 '13 at 08:19

1 Answers1

1

Well for starters, looks like the data could be considered analogous to an NSDictionary.

You could take this string as an NSString and get an NSArray by sending the message componentsSeparatedByString: with an arg of @"&".

NSArray *firstArray = [responseString componentsSeparatedByString:@"&"];

Then create an NSMutableDictionary

NSMutableDictionary *mDict = [[ NSMutableDictionary alloc] initWithCapacity: firstArray.count ];

Then use fast enumeration to populate the key value pairs.

for ( NSString *aKVP in firstArray) {
    NSArray *tempArray = [aKVP componentsSeparatedByString:@"="];
    [mDict setValue: tempArray[1] forKey: tempArray[0] ];
}

Then you have a data structure you can use. You can access the values by key to set button labels or whatever else you want to do.

Other approaches would include things like NSScanner or NSRegularExpression but this is straight forward and flexible if you need the rest.

mttrb
  • 8,297
  • 3
  • 35
  • 57
uchuugaka
  • 12,679
  • 6
  • 37
  • 55
  • @mttrb I have one doubt i have getting all values from tempArray like dis ( usertypecode, ROBT ) how can i show ROBT only in one label i have getting lot of values like dis in temparray( "email_id", "test1@test.com" ) tempArray ( "user_currency_code", USD ) – Balaji Sep 02 '13 at 05:42
  • Just take the value you want. – uchuugaka Sep 02 '13 at 05:44
  • i dont know that how to get that values and show in label i am new for iphone .Please help me out dis problem – Balaji Sep 02 '13 at 05:46