簡體   English   中英

JSON解析返回null

[英]JSON parse returns null

我需要解析Apple JSON,但是我有一個小問題。 我現在正在這樣做:

問題在這里:

- (void)fetchedData:(NSData *)responseData {
    NSError* error;
    NSDictionary* json = [NSJSONSerialization JSONObjectWithData:responseData
                                                         options:kNilOptions 
                                                           error:&error];



    NSNumber *resultCount = [json objectForKey:@"resultCount"];
    NSLog(@"%i", [resultCount intValue]);

    NSArray * AppStoreUrlParse = [json objectForKey:@"results"]; 

    NSDictionary* StoreParse = [AppStoreUrlParse objectAtIndex:0];

    NSLog(@"%@", [json objectForKey:@"price"]);

}

在這行上:

    NSLog(@"%i", [resultCount intValue]);

NSlog正在重播:1類似於JSON( http://itunes.apple.com/lookup?id=387633954

但是在這條線上

    NSLog(@"%@", [json objectForKey:@"price"]);

NSLOG返回(空)

有誰知道我怎么能從json獲得價格?

似乎“價格”是字典的一部分,而字典是“結果”數組中的第一項。

你能試一下嗎

NSLog(@"%@", [[AppStoreUrlParse objectAtIndex:0] objectForKey:@"price"]);

這將在JSON的“結果”數組的第一個元素中獲取鍵“價格”的值。

編輯

實際上,重新讀取代碼,您已經在此行中獲得了數組的第一個元素:

NSDictionary* StoreParse = [AppStoreUrlParse objectAtIndex:0];

因此,您要做的就是在NSLog中通過StoreParse更改json

NSLog(@"%@", [StoreParse objectForKey:@"price"]);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM