如何在Objective-C中访问另一个数组中的数组索引

jay*_*ixz 0 indexing xcode objective-c nsarray

我有这个数组,我想访问另一个数组中的第一个索引.

(
    (
        1021,
        "String1,
        "<null>",
        "name1, name2",
        P,
        "String2",
        "Link1",
        "String3",
        "String4"
    ),
    (
        1025,
        "String1",
        "<null>",
        "name1, name2"
        P,
        "String2",
        "Link1",
        "String3",
        "String4"
    )
)
Run Code Online (Sandbox Code Playgroud)

我尝试使用此代码的NSLog:

NSLog(@"ID: %@", [[array objectAtIndex:0] objectAtIndex:0]);
Run Code Online (Sandbox Code Playgroud)

但它不起作用.它给我一个错误说:

-[__NSCFString objectAtIndex:]: unrecognized selector sent to instance
Run Code Online (Sandbox Code Playgroud)

我只想在第一个数组的第一个数组中记录值1021.

dre*_*lax 6

您面临的问题是,array或者第一个元素array是字符串.

将其分开并逐步调试,以确保正确加载和访问数组:

NSArray *array = [NSArray /* load from somwhere */];
NSLog(@"%@", array);

NSArray *innerArray = [array objectAtIndex:0];
NSLog(@"%@", innerArray);

NSNumber *objectId = [innerArray objectAtIndex:0];
NSLog(@"%@", objectId);
Run Code Online (Sandbox Code Playgroud)