从数组JSON,Xcode中提取变量

时间:2015-03-19 17:29:25

标签: arrays json xcode

我对这个XCODE目标C非常新,浏览论坛无法得到我需要的东西。我试图从数组中提取一个特定的值。即时通讯使用teleduino,网络服务,只是让你了解它。所以嗯..我不知道为什么我没有得到这个值的输出" 328-0.6.9"如附图所示。我不需要其他数据只是一个数据。

xcode的输出



2015-03-20 01:17:19.987 APItest[1686:56954] Succeeded! Received 100 bytes of data
2015-03-20 01:17:19.988 APItest[1686:56954] key: status
2015-03-20 01:17:19.988 APItest[1686:56954] value: 200
2015-03-20 01:17:19.989 APItest[1686:56954] key: message
2015-03-20 01:17:19.989 APItest[1686:56954] value: OK
2015-03-20 01:17:19.989 APItest[1686:56954] key: response
2015-03-20 01:17:19.990 APItest[1686:56954] value: {
    result = 1;
    time = "0.57582592964172";
    values =     (
        "328-0.6.9"
    );




我的代码



    // convert to JSON
    NSError *myError = nil;
    NSDictionary *res = [NSJSONSerialization JSONObjectWithData:self.responseData options:NSJSONReadingMutableLeaves error:&myError];
    
    // show all values
    for(id key in res) {
        
        id values = [res objectForKey:key];
        
        NSString *keyAsString = (NSString *)key;
        NSString *valueAsString = (NSString *)values;
        
       NSLog(@"key: %@", keyAsString);
        NSLog(@"value: %@", valueAsString);
    }
   
     //extract specific value...
    NSArray *value = [res objectForKey:@""];
    
    for (NSDictionary *values in value) {
        NSString *icon = [values objectForKey:@"icon"];
        NSLog(@"icon: %@", icon);
        }




1 个答案:

答案 0 :(得分:0)

查看日志,值是一个字符串数组。请尝试以下方法:

//extract specific value...
NSArray * values = [res objectForKey:@"values"];

for (NSString *value in values) {

    NSLog(@"icon: %@", value);
}