XML and JSON for network parsing, and xmljson for parsing
First, add the class library GDataXMLNode and JSON
Students.txt
<Students>
<Student>
<Name> Tom </name>
<Age> 20 </age>
<Phone> 13049640144 </phone>
</Student>
<Student>
<Name> Jimmy </name>
<Age> 20 </age>
<Phone> 13049640144 </phone>
</Student>
<Student>
<Name> screw </name>
<Age> 20 </age>
<Phone> 13049640144 </phone>
</Student>
</Students>
// XML Parsing
NSString * str = [NSString stringWithContentsOfFile: [[NSBundle mainBundle] pathForResource: @ "Students" ofType: @ "txt"] encoding: NSUTF8StringEncoding error: nil];
// Parse XML and put the result in the document
GDataXMLDocument * document = [[GDataXMLDocument alloc] initWithXMLString: str options: 0 error: nil];
GDataXMLElement * root = [document rootElement]; // obtain the root node
NSArray * arr = [root nodesForXPath: @ "// name" error: nil];
// Traverse nodes
For (GDataXMLElement * name in arr)
{
NSLog (@ "% @", [name stringValue]);
}
// Json Parsing
NSString * str = @ "[{\" name \ ": \" kelly \ ", \" age \ ": \" 23 \ ", \" sex \": \ "female \" },{ \ "name \": \ "evnxy \", \ "age \": \ "21 \", \ "sex \": \ "female \"}] ";
NSArray * arr = [str JSONValue];
NSLog (@ "% @", arr );