2014-02-12 35 views
-2

我想在这样一个URL解析JSON的URL“和空间:无法解析包含在Xcode

NSError *error = nil; 
    NSString *sampleUrl= @"http://xbmc:[email protected]:8080/jsonrpc?request={\"jsonrpc\":%20\"2.0\",%20\"method\":%20\"VideoLibrary.GetMovies\",%20\"params\":%20{%20\"filter\":%20{\"field\":%20\"playcount\",%20\"operator\":%20\"is\",%20\"value\":%20\"0\"},%20\"limits\":%20{%20\"start\"%20:%200,%20\"end\":%2075%20},%20\"properties\"%20:%20[\"art\",%20\"rating\",%20\"thumbnail\",%20\"playcount\",%20\"file\"],%20\"sort\":%20{%20\"order\":%20\"ascending\",%20\"method\":%20\"label\",%20\"ignorearticle\":%20true%20}%20},%20\"id\":%20\"libMovies\"}"; 
    NSLog(@"%@ ",sampleUrl); 

    NSData *jsonData = [NSData dataWithContentsOfURL:[NSURL URLWithString:sampleUrl]]; 

    id jsonObjects = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:&error]; 

,但我得到一个错误,指出:

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'data parameter is nil' 

当我在我的浏览器中复制我的网址: 但我没有试过xcode 我试着改变了设置“减少了22%,并且消除了\:不起作用!

我该如何继续? 谢谢

+0

什么结果ü需要 –

+0

我需要电影例如列表... –

+0

正确的网址是:http://192.168.1.66:8080/jsonrpc?request={"jsonrpc“:”2.0“,”method“:”VideoLibrary.GetMovies“,”params“:{”filter“:{”field “:”playcount“,”operator“:”is“,”value“:”0“},”limits“:{”start“:0,”end“:75},”properties“:[”art“, “评分”,“缩略图”,“playcount”,“文件”],“排序”:{“order”:“升序”,“method”:“label”,“ignorearticle”:true}}, ID“:”libMovies“} –

回答

0

问题是sampleUrl中的字符串不是格式正确的URL(请参阅RFC 1738)。

它包含URL中不允许的各种字符,例如{"。在转换为NSURL之前,这些字符必须进行百分比转义。

你的URL字符串究竟来自哪里?

+0

sry兄弟我复制了一些行 –

+0

我的网址是例子:http://wiki.xbmc.org/index.php?title=JSON-RPC_API和这里:http://wiki.xbmc.org/index.php?title=JSON-RPC_API/例子 –

+0

我的网址是示例:http://wiki.xbmc.org/index.php?title=JSON-RPC_API和here:http://wiki.xbmc.org/index.php?title=JSON-RPC_API/实例 –

-1

这里是可以创造奇迹的结果:

NSString *urlString = [NSString stringWithFormat:@"http://xbmc:[email protected]:8080/jsonrpc?request={\"jsonrpc\": \"2.0\", \"method\": \"VideoLibrary.GetMovies\", \"params\": { \"filter\": {\"field\": \"playcount\", \"operator\": \"is\", \"value\": \"0\"}, \"limits\": { \"start\" : 0, \"end\": 75 }, \"properties\" : [\"art\", \"rating\", \"thumbnail\", \"playcount\", \"file\"], \"sort\": { \"order\": \"ascending\", \"method\": \"label\", \"ignorearticle\": true } }, \"id\": \"libMovies\"}"]; 
    NSLog(@"%@ ",sampleUrl); 
    NSString *encodedUrl = [urlString stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding]; 
    NSURL *url = [[NSURL alloc] initWithString:encodedUrl]; 


    NSData *jsonData = [NSData dataWithContentsOfURL:[NSURL URLWithString:encodedUrl]]; 

    id jsonObjects = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:&error]; 

谢谢大家的帮助;)

相关问题