gpt4 book ai didi

ios - URL 作为 Xcode 中的字符串和值

转载 作者:行者123 更新时间:2023-11-28 19:02:25 25 4
gpt4 key购买 nike

我正在开发一个网络服务应用程序,我有一个问题。我正在使用以下代码调用特定的 Url 站点:

NSURL *Url = [NSURL URLWithString:[requestStream stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];

NSString *htmlString = [NSString stringWithContentsOfURL:Url encoding:NSUTF8StringEncoding error:&error];

然后我创建一个 nsstring 并使用 NSLog 打印它,我得到以下结果:

2014-05-14 15:50:58.118 jsonTest[1541:907] Data : Array
(
[url] => http://sheetmusicdb.net:8000/hnInKleinenGruppen
[encoding] => MP3
[callsign] => SheetMusicDB.net - J
[websiteurl] =>
)

我的问题是如何解析 URL 链接,然后将其用作值?我试图将它们放入数组或字典中,但出现错误。因此,如果有人可以帮助我,我将不胜感激。

好的,我设法通过以下代码获取了链接:

if(htmlString) {
//NSLog(@"HTML %@", htmlString);

NSRange r = [htmlString rangeOfString:@"=>"];
if (r.location != NSNotFound) {
NSRange r1 = [htmlString rangeOfString:@"[encoding]"];
if (r1.location != NSNotFound) {
if (r1.location > r.location) {
_streamTitle = [htmlString substringWithRange:NSMakeRange(NSMaxRange(r), r1.location - NSMaxRange(r))];
NSLog(@"Title %@", _streamTitle);
}
}
}
} else {
NSLog(@"Error %@", error);
}

感谢您的建议。我现在的问题是,我将字符串传递给 avplayer,但我听不到音乐。

最佳答案

我想这对你有帮助..

// @property (nonatomic,retain) NSMutableData *responseData;
// @synthesize responseData;

NSString *urlString=@"http:your urls";
self.responseData=[NSMutableData data];
NSURLConnection *connection=[[NSURLConnection alloc]initWithRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:urlString]] delegate:self];
NSLog(@"connection====%@",connection);

JSON 委托(delegate):

 -(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
[self.responseData setLength:0];
}
-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
[self.responseData appendData:data];
}
-(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
{
self.responseData=nil;
}
-(void)connectionDidFinishLoading:(NSURLConnection *)connection
{
NSArray *response_Array = [NSJSONSerialization JSONObjectWithData:self.responseData options:kNilOptions error:nil];

// Write code for retrieve data according to your Key.
}

关于ios - URL 作为 Xcode 中的字符串和值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23655562/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com