0

それは一例です

{
"updated":1350213484,
"id":"http://www.google.com/reader/api/0/feed-finder?q\u003dProva\u0026output\u003djson",
"title":"Risultati di feed per \"Prova\"",
"self":[
{
"href":"http://www.google.com/reader/api/0/feed-finder?q\u003dProva\u0026output\u003djson"
}
],
"items":[
{
"title":"Home Page - La prova del cuoco",
"id":"http://www.laprovadelcuoco.rai.it/",
"updated":1350213485,
"feed":[
{
"href":"http://www.laprovadelcuoco.rai.it/dl/portali/site/page/Page-ffb545b4-9e72-41e5-866f-a465588c43fa-rss.html"
}
],
"alternate":[
{
"href":"http://www.laprovadelcuoco.rai.it/",
"type":"text/html"
}
],
"content":{
"direction":"ltr",
"content":"Diventa un cuoco provetto con “La Prova del Cuoco”: le videoricette in un' applicazione di facile e veloce consultazione per il tuo Iphone. Scopri come acquistare ..."
}
},
{
"title":"Le prove Invalsi di matematica e italiano",
"id":"http://online.scuola.zanichelli.it/quartaprova/",
"updated":1350213486,
"feed":[
{
"href":"http://online.scuola.zanichelli.it/quartaprova/feed/"
}
],
"alternate":[
{
"href":"http://online.scuola.zanichelli.it/quartaprova/",
"type":"text/html"
}
],
"content":{
"direction":"ltr",
"content":"Un sito Zanichelli dedicato alle prove Invalsi di italiano e matematica: esercitazioni, consigli, informazioni utili, novità, aggiornamenti e blog d'autore sulle prove ..."
}
},

フィードの URL を取得するにはどうすればよいですか?

それが私がすることです

NSString *daParsare=[reader searchFeed:searchText];



NSArray *items = [[daParsare JSONValue] objectForKey:@"items"];

for (NSDictionary *item in items) {



    NSString *title = [item objectForKey:@"title"];
    NSString *feed = [item valueForKeyPath:@"feed.href"];


}
[tab reloadData];

タイトルはすべて問題ありませんが、フィードパラメーターにアクセスしようとするとエラーが発生します...

4

2 に答える 2

1

JSON オブジェクトの名前がjsonObjectであると仮定すると、単純に要素にアクセスできますhref。したがって、現在のオブジェクトでは、URL は という名前のオブジェクトにあります。これは、最上位で名前がhref付けられた配列の最初の (この場合は唯一の) 要素です。feed

NSString* urlString = jsonObject[@"feed"][0][@"href"];

feedその要素の 1 つにアクセスする前に、存在する場合は空の配列ではないことを確認する必要があります。

于 2012-10-14T14:40:15.223 に答える
0
NSString *feed = [item valueForKeyPath:@"feed.href"];

feed再び辞書を保持する配列を参照すると、間違っています。

NSString *feed = [[[item objectForKey:@"feed"] objectAtIndex:0] objectForKey:@"href"];

最新の Xcode を使用している場合、この最後の行は Jason Cocos の回答と同じです。

NSString* feed = item[@"feed"][0][@"href"];

この構文はObject Subscriptionと呼ばれます。

于 2012-10-14T15:22:37.580 に答える