我试图从以下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(*将是通配符)
答案 0 :(得分:0)
没有。您将不得不循环键入/值,如*:
...
NSDictionary *data = [JSON valueForKey:@"data"];
for (NSString *movie in data) {
NSLog(@"tvrage_name: %@", [[data valueForKey:movie] valueForKey:@"tvrage_name"]);
}
...
*我喜欢安全,所以我总是要额外检查。例如[JSON isKindOfClass:[NSDictionary class]]
等等。
希望它有所帮助。
答案 1 :(得分:0)
如果您只收到电视节目条目的字典副本(而不是'消息'结果'),那么您可以/**
* @license Copyright (c) 2003-2015, CKSource - Frederico Knabben. All rights reserved.
* For licensing, see LICENSE.md or http://ckeditor.com/license
*/
CKEDITOR.editorConfig = function( config ) {
// Define changes to default configuration here. For example:
config.language = 'fr';
// config.uiColor = '#AADC6E';
config.extraPlugins = 'coops';
config.extraPlugins = 'change';
config.extraPlugins = 'coops-connector';
config.extraPlugins = 'coops-dmp';
config.extraPlugins = 'coops-cursors';
config.readOnly = true;
coops: {
serverUrl: '/files/';
}
};
这应该有效,因为allValues为您提供了一个字典数组,因此valueForKeyPath将为您提供给定键下的值数组。
(但是,如果JSON没有按照您的预期构建,那么在网络上获取JSON时,如果没有额外的检查或强化,这可能是个坏主意)