[英]NSMutableData response string
I am trying to upload images to yFrog which is working just fine, but I want to grab just the URL from the response. 我正在尝试将图片上传到yFrog,效果很好,但是我只想从响应中获取URL。 When I use the
NSURLConnection
method 当我使用
NSURLConnection
方法时
- (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. 如您所见,在我被阻止的代码中,我试图给
NSMutableData
赋予我崩溃的键@“ mediaurl”的值。 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. 我认为这应该相对容易一些,但是由于某些原因,我只是想不出如何从响应中获取URL。 Any help would be greatly appreciated.
任何帮助将不胜感激。 Thank you
谢谢
This is a valid xml response. 这是有效的xml响应。
If you need to parse only this response, you can iterate the NSString
. 如果只需要解析此响应,则可以迭代
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.. :) 但是,如果您还有其他xml格式的响应,那么最好的方法是使用任何XML解析器来解析它。
Here is how to choose your xml parser, and then you will search for tutorial accordingly. 这是选择xml解析器的方法,然后您将相应地搜索教程。
您不能在NSMutableData
类的实例上使用valueForKey
。应该使用XML解析器来提取值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.