程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> 編程綜合問答 >> ios-AFNetworking valueForKeyPath通配符

ios-AFNetworking valueForKeyPath通配符

編輯:編程綜合問答
AFNetworking valueForKeyPath通配符

我正在從下面的JSON文件中獲取tvrage_name:

{
    data: {
           Band of Brothers: {
                              air_by_date: 0,
                              cache: {
                                      banner: 1,
                                      poster: 1
                                      },
                              language: "en",
                              network: "HBO",
                              next_ep_airdate: "",
                              paused: 0,
                              quality: "Any",
                              status: "Ended",
                              tvdbid: 74205,
                              tvrage_id: 2708,
                              tvrage_name: "Band of Brothers"
                              },
           Breaking Bad: {
                              air_by_date: 0,
                              cache: {
                              banner: 1,
                              poster: 1
                              },
                              language: "en",
                              network: "AMC",
                              next_ep_airdate: "2013-07-14",
                              paused: 0,
                              quality: "HD",
                              status: "Continuing",
                              tvdbid: 81189,
                              tvrage_id: 18164,
                              tvrage_name: "Breaking Bad"
                              },
          },
          message: "",
          result: "success"
}

能不能在valueForKeyPath中有一個通配符?這樣valueForKeyPath可以成為:data.*.tvrage_name(其中*就是通配符)

最佳回答:


你需要去遍歷值/key,像這樣:

...
NSDictionary *data = [JSON valueForKey:@"data"];
for (NSString *movie in data) {
    NSLog(@"tvrage_name: %@", [[data valueForKey:movie] valueForKey:@"tvrage_name"]);
}
...

為了保險起見我會做額外的檢查e.g. [JSON isKindOfClass:[NSDictionary class]]

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved