Objective c JSON解析错误(空白响应)

Objective c JSON解析错误(空白响应),objective-c,json,Objective C,Json,这是我的代码,当我运行它时,我得到:2014-10-26 19:02:09.153应用程序[27372:1281902]价格: 我想知道为什么,没有错误被传递,这让我很困惑 我得到了一个关于omc_美元_价格的空白回复 @try { NSURL *url = [NSURL URLWithString:@"https://omnicha.in/api?method=getinfo"]; NSData *data=[NSData dataWithContentsOfURL:url]

这是我的代码,当我运行它时,我得到:2014-10-26 19:02:09.153应用程序[27372:1281902]价格:

我想知道为什么,没有错误被传递,这让我很困惑

我得到了一个关于omc_美元_价格的空白回复

@try
{
    NSURL *url = [NSURL URLWithString:@"https://omnicha.in/api?method=getinfo"];
    NSData *data=[NSData dataWithContentsOfURL:url];
    NSError *error;

    NSMutableDictionary *JSONStuff= [NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingMutableContainers error: &error];

    NSLog(@"%@",JSONStuff);

    NSMutableArray * OMCArray = [[NSMutableArray alloc]init];

    NSArray * responseArr = JSONStuff[@"omc_usd_price"];

    for(NSDictionary * dict in responseArr)
    {
        [OMCArray addObject:[dict valueForKey:@"omc_usd_price"]];

    }


    NSLog(@"Price: %@ test", OMCArray);   // Here you get the Referance data
}
@catch (NSException *exception) {
    NSLog(@"%@", exception);

}
@finally {

}
编辑:

试过了,我也不认为我做得对

NSMutableArray * OMCArray = [[NSMutableArray alloc]init];
    NSMutableArray * OMCArray2 = [[NSMutableArray alloc]init];

    NSArray * responseArr = JSONStuff[@"response"];
    NSArray * responseArr2 = JSONStuff[@"omc_usd_price"];

    for(NSDictionary * dict in responseArr)
    {
        [OMCArray addObject:[dict valueForKey:@"response"]];

        for(NSDictionary * dict2 in responseArr2)
        {
            [OMCArray addObject:[dict2 valueForKey:@"omc_usd_price"]];
        }
    }


    NSLog(@"Price: %@ test", OMCArray2);   // Here you get the Referance data

以下是JSONSTAFF字典:

{
    "error":false,
    "response":{
        "block_count":96136,
        "difficulty":12.18364177,
        "netmhps":234.652099,
        "seconds_since_block":694,
        "avg_block_time":196.533,
        "total_mined_omc":6426691.6,
        "omc_btc_price":7.0e-6,
        "omc_usd_price":0.0025,
        "market_cap":15833.5909
    }
}

如您所见,字典中没有名为omc_usd_price的条目。dictionary name响应中有一个同名条目,但您没有要求它。

如果您想获得代码中提到的omc_usd_价格,则需要解析2个字典。 您必须首先用键响应解析字典,这将为您提供一个新字典

然后在这个新字典中,您必须解析/查找关键omc_usd_价格


另外,你得到的不是数组,而是一个double或float,甚至是一个字符串。

如果jsonstaff[@omc\u usd\u price]为空或为零,你可以得到它。由于字典JSONSTAFF中没有一个条目名为omc_usd_price,这是意料之中的。你是对的,这是不对的。你能详细说明我如何解决这个问题吗?对不起,我不太擅长ObjC。你的字典里有一本字典。获取内部字典,然后要求您在其中输入价格。我尝试了其他一些我认为你们的意思-也不起作用。提示:使用NSLog显示JSONStuff[@error]和JSONStuff[@response]的值。我得到了一个显示“error”和“response”的空格,使用以下代码:NSLog@%@,JSONStuff[@response];