Converting Objects to plist file then to data - iphone

I have an array of objects that consist of several strings, I need to push these up to a web service as XML data. What are the steps involved here? As far as I know I need to convert the objects to a plist file, then convert this file to NSData (?) I can't find anything online that really lays it out..
Any help would be greatly appreciated.

Another approach is JSON. SBJSON is very common and simple to use.
It's a two-liner to get a json string from your array. Then you'll create an NSURLRequest that represents the post and an NSURLConnection that performs the request. Lot's of resources for that on SO and elsewhere.

You can try this or this. I doubt plist files are what you want. All you need is to serialize your object into the xml format your web service requires.

Related

Where can I find an Objective C code which parses any XML file without knowing before any tag or attribute?

I would like to find a sample of code written in Objective C for iPhone which can parse any XML file, even if we don't know tags or attributes. Does anyone has something like that?
Probably you can convert the XML into a NSDictionary which then can be used at your ease.
I have not used this code, but maybe you can try this to convert your xml into dictionary
http://troybrant.net/blog/2010/09/simple-xml-to-nsdictionary-converter/

How to create XML editor for iPhone?

I want to create a XML editor (form view type) for iphone. Can anyone suggest me how to proceed in this regard. I know how to parse an XML document but I am having trouble in editing the contents of the file dynamically. This editor should be such that, a new node can be added or a node can be deleted, it can also edit the values.
Please help...
In short you need to parse the document into a readable structure, finding a way to modify that structure, and write it back to XML.
Classes you are likely to need to write include MyXMLDocument, MyXMLNode, MyXMLElement and MyXMLTextNode, and MyXMLNode likely needs NSArray *children;, MyXMLNode *parent; and MyXMLDocument *document; as ivars.
You also probably need something akin to a -stringValue method; and an understanding of how the XML DOM usually works.

how can i replace json string?

i want to replace particular data's in json string
Parse it, make the changes you need, then serialize it back out. You didn't say what JSON library you're using, but it should be fairly easy.
Without knowing the specifics of your problem:
[jsonString stringByReplacingOccurrencesOfString:#"replaceme" withString:#"replacement"];
But you're probably far better of using a JSON library.

Parse JSON array

I fetch a JSON array from a web service with touchJSON.
Which looks like this:
[{"icecream": {"title": "Banana"}}, {"icecream": {"title": "Strawberry"}}]
I'm not able to parse this into a NSDictionary, because
touchJSON doesn't support JSON arrays.
How do I get my JSON array into a NSDicitionary?
Regards
Have you consider trying another framework? This one seems to support JSON arrays.
Maybe you could use another of the many JSON implementations listed on the JSON homepage.
You can chekc out the JSON webpage, where they provide links to parsing code in dozens of languages. However, at first glance it looks like you're trying to munge from one type of object (the JSON Array) into another that might not be able to capture all the relationships (the NSDictionary). Full disclaimer: I've never used an NSDictionary before.

How do I read and write XML in Cocoa Touch?

I want to create a file using Objective-C, which stores the data comes from XML. I also have to do basic functions of read and write into that file. How can I do this?
You can parse a custom schema using the NSXMLParser class. This is especially useful since the NSXMLDocument class unfortunately does not exist on the iPhone. Thankfully, NSXMLParser is pretty easy to use. I've written an RSS feed parser using NSXMLParser in under half an hour.
If you have some flexibility over the XML structure, you could look at using the in-built commands to load and save a dictionary or array from/to a file, such as:
NSDictionary *myDict = [[NSDictionary alloc] initWithContentsOfFile:myFileName];
This will load in an XML file into a dictionary. It expects the file to be in the format
<key>Object 1</key><string>ContentsOfObject1</string>
<key>Object 2</key><string>ContentsOfObject2</string> etc
(You can also init an array in the same way. The file is simpler, basically just leaving out the "key" part).
Then, to save it you just use the following command:
[self.myArrayorMyDictionary writeToFile:fileFullName atomically:YES];
Hope that helps!