NSMutableData response string

戏子无情 提交于 2019-12-11 04:35:44

问题


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


回答1:


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.




回答2:


you can't use the valueForKey on the instance of NSMutableData class., you should use the XML parser to extract the value.



来源:https://stackoverflow.com/questions/8921602/nsmutabledata-response-string

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!