I use a “get” request to receive a list of a data from a server. I have all of the NSURLConnection stuff working and receive the data ok. I am running into trouble actually parsing the data.
When the data is returned it is in a format like so:
[{"item":{"name":"xxx", "address":"xxx"}, "url":"xxx", "message":"xxx"}, {"item":{"name":"xxx", "address":"xxx"}, "url":"xxx", "message":"xxx"}.....]
Right now I have tried setting up the response data as an NSXMLDocument, then setting up this:
NSString *xpathQueryString =
@"";
NSArray *newItemsNodes = [rootNode nodesForXPath:xpathQueryString error:&error];
to get the nodes and parse through. But it does not work 🙁
I am not sure if this is the best way to go about this or if maybe my xpathQueryString is wrong.
Any help would be very much appreciated! Thank you for your time.
The text you are receiving is formatted as JSON, so you need to you a JSON Parser, rather than an XML Parser.
In iOS 5 there is a JSON parser included (NSJSONSerialisation), but if you are targeting systems running less than iOS 5, you need to use an external parser, such as JSONKit. Although JSONKit is actually more efficient than the one included in iOS5, so you’re better off using it no matter what.