それはしばらくの間それを見て、私の知識のあらゆる可能な方法を試しましたが、まだ成功しませんでした。JSONを配列からNSDictionaryに解析しますか? (ObjC)
次のJSONを解析して最初の配列を辞書に取得するにはどうすればよいですか?今、私はNSDictionaryのに最初の配列を取得する方法)
を
(
y,
(
yeti,
"yeti tumbler",
"yoga pants",
"yoga mat",
"yeezy boost 350",
"yeti cup",
yoga,
yeezy,
"young living essential oils",
yugioh
),
(
{
nodes = (
{
alias = garden;
name = "Home & Kitchen";
},
{
alias = "outdoor-recreation";
name = "Outdoor Recreation";
},
{
alias = "fan-shop";
name = "Sports Fan Shop";
}
);
},
{
},
{
},
{
},
{
},
{
},
{
},
{
},
{
},
{
}
),
(
)
:私はAFNetworkingライブラリを使用していますし、responseObjectは、次の値を返しますか?
(
yeti,
"yeti tumbler",
"yoga pants",
"yoga mat",
"yeezy boost 350",
"yeti cup",
yoga,
yeezy,
"young living essential oils",
yugioh
)
にObjCコード:
- (void)requestJSONWithQuery:(NSString *)query
{
if (!_requestOperation.isCancelled) [_requestOperation cancel];
query = [query stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSString *string = [NSString stringWithFormat:_URLDictionaryForAPIs[@(_APIType)], query];
NSURL *url = [NSURL URLWithString:string];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
_requestOperation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
_requestOperation.responseSerializer = [AFJSONResponseSerializer serializer];
__block FFFGoogleSearchAutoCompleteController *selfInBlock = self;
[_requestOperation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
// NSLog(@"%@", responseObject);
selfInBlock.suggestions = [(NSDictionary *)responseObject mutableArrayValueForKey:query];
[selfInBlock refreshSuggestionTable];
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
}];
[_requestOperation start];
}
これは、次のエラーを返します:
Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<NSTaggedPointerString 0xa0000000000006b1> valueForUndefinedKey:]: this class is not key value coding-compliant for the key K.'
?あなたの目的は何ですか?あなたの鍵は何ですか? – headbanger
'query'の値は何ですか? 'responseObject'は何を印刷しますか? 'responseObject'の最初のプリントの外観によって、多次元配列のように見えます。 – Larusso
responseObjectは上記の投稿の最初のコードブロックを出力します。クエリの値は挿入されたテキストです。 JSONファイルは次のようになります。http://completion.amazon.com/search/complete?search-alias=aps&client=amazon-search-ui&mkt=1&q=k – Jan