I am trying to upload images to yFrog which is working just fine, but I want to grab just the URL from the response. When I use the NSURLConnection
method
- (void) connectionDidFinishLoading:(NSURLConnection *)connection {
[connection release];
NSString* responseString = [[NSString alloc] initWithData:webData
encoding:NSUTF8StringEncoding];
// NSString *url = [webData valueForKey:@"mediaurl"];
NSLog(@"result: %@", responseString);
}
I get this as my response string
result: <?xml version="1.0" encoding="UTF-8"?>
<rsp stat="ok">
<mediaid>hszuhsp</mediaid>
<mediaurl>http://yfrog.com/hszuhsp</mediaurl>
</rsp>
As you can see in my blocked out code I tried to give my NSMutableData
to give me the value of the key @"mediaurl" which just crashes. I think this should be relatively easy but for some reason I just can not figure out how to just grab the URL out of the response. Any help would be greatly appreciated. Thank you
This is a valid xml response.
If you need to parse only this response, you can iterate the
NSString
.But if you have other response in xml format then the best approach is you are going to parse it using any XML parser.. :)
Here is how to choose your xml parser, and then you will search for tutorial accordingly.
you can't use the
valueForKey
on the instance ofNSMutableData
class., you should use the XML parser to extract the value.