2

i want to write NSString into NSMutableArray.Please look at the following code:

NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil        error:nil];

NSString *returnString = [[NSString alloc] initWithData:returnData encoding:NSUTF8StringEncoding];
returnString = [returnString stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
NSLog(returnString);

Here i get some response(a plist file) from a server which i saved as NSData and then convert it to NSString.When i print this NSString it looks like following.

<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<array>
<string>sourav sas</string>
<string>dipto pol</string>
<string>Shahriar Alam</string>
<string>toukir naim</string>
<string>shamim mohiuddin</string>
</array>
</plist>

Now i want to copy this NSString into an NSMutableArray.Each index of NSMutable array will contain the names between tag. How can i do that.

2 Answers 2

2
NSMutableArray *array = [NSPropertyListSerialization propertyListFromData:data
                                                         mutabilityOption:NSPropertyListMutableContainers 
                                                                   format:NULL 
                                                         errorDescription:NULL];
Sign up to request clarification or add additional context in comments.

2 Comments

You mean i can convert NSData directly to NSMutable Array?
Yes, you can. Take a look at documentation about NSPropertyListSerialization. Property list programming guide is also very useful.
2

You need to use NSXMLParser. See this tutorial:

http://codesofa.com/blog/archive/2008/07/23/make-nsxmlparser-your-friend.html

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.