NSMutableData 响应字符串 [英] NSMutableData response string

查看:50
本文介绍了NSMutableData 响应字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将图像上传到 yFrog,它工作正常,但我只想从响应中获取 URL.当我使用 NSURLConnection 方法时

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> 

正如你在我被屏蔽的代码中看到的,我试图给我的 NSMutableData 给我刚刚崩溃的键 @"mediaurl" 的值.我认为这应该相对容易,但由于某种原因,我无法弄清楚如何从响应中获取 URL.任何帮助将不胜感激.谢谢

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

推荐答案

这是一个有效的 xml 响应.

This is a valid xml response.

如果你只需要解析这个响应,你可以迭代NSString.

If you need to parse only this response, you can iterate the NSString.

但是如果您有其他 xml 格式的响应,那么最好的方法是您将使用任何 XML 解析器来解析它.. :)

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解析器,然后你会相应地搜索教程.

Here is how to choose your xml parser, and then you will search for tutorial accordingly.

这篇关于NSMutableData 响应字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆