キーなしで JSON を解析しようとしています。次のようになります。
{
"somestring": [
"otherstring1",
float],
"somestring2": [
"somestring3",
float],
"full":integer
}
各オブジェクトの最初の値を解析するにはどうすればよいですか?
キーなしで JSON を解析しようとしています。次のようになります。
{
"somestring": [
"otherstring1",
float],
"somestring2": [
"somestring3",
float],
"full":integer
}
各オブジェクトの最初の値を解析するにはどうすればよいですか?
したがって、それを解析するとNSDictionary
、最初の 2 つのキーの値が である with が得られますNSArray
。
NSDictionary *dictionary = [NSJSONSerialization JSONObjectWithData:data options:0 error:&error];
if (error)
NSLog(@"JSONObjectWithData error: %@", error);
NSArray *array = dictionary[@"22398f2"];
NSString *firstArrayItem = array[0]; // @"CBW32"
NSString *secondArrayItem = array[1]; // @50.1083
または、最初のすべての項目が必要な場合は、次のようにすることができます。
NSDictionary *dictionary = [NSJSONSerialization JSONObjectWithData:data options:0 error:&error];
if (error)
NSLog(@"JSONObjectWithData error: %@", error);
[dictionary enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) {
NSArray *array = obj;
if ([obj isKindOfClass:[NSArray class]])
NSLog(@"first item = %@", array[0]);
else
NSLog(@"The value associated with key '%@' is not array", key);
}];